com.backblaze.b2.json.B2JsonUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of b2-sdk-core Show documentation
Show all versions of b2-sdk-core Show documentation
The core logic for B2 SDK for Java. Does not include any implementations of B2WebApiClient.
/*
* Copyright 2017, Backblaze Inc. All Rights Reserved.
* License https://www.backblaze.com/using_b2_code.html
*/
package com.backblaze.b2.json;
import java.io.IOException;
public class B2JsonUtil {
/**
* Serialize an object that may be null.
*/
public static void serializeMaybeNull(B2JsonTypeHandler handler, T obj, B2JsonWriter out) throws IOException, B2JsonException {
if (obj == null) {
out.writeText("null");
}
else {
handler.serialize(obj, out);
}
}
/**
* Deserialize an object that may be null.
*/
public static T deserializeMaybeNull(B2JsonTypeHandler handler, B2JsonReader in, int options) throws B2JsonException, IOException {
if (in.peekNextNotWhitespaceChar() == 'n') {
in.readNull();
return null;
}
else {
return handler.deserialize(in, options);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy