[]
Implement this interface to convert application-specific objects to JSON strings and to reconstruct those objects when a workbook is converted to or from JSON. This interface is typically used with Workbook.setTagJsonSerializer(IJsonSerializer) or Workbook.setValueJsonSerializer(IJsonSerializer).
IJsonSerializer serializer = new IJsonSerializer() {
private final com.google.gson.Gson gson = new com.google.gson.Gson();
@Override
public String serialize(Object value) {
return gson.toJson(java.util.Collections.singletonMap("value", value));
}
@Override
public Object deserialize(String json) {
return gson.fromJson(json, java.util.Map.class);
}
};
Workbook.setValueJsonSerializer(serializer);
Implement this method to convert a custom value into JSON text that can be used during JSON import and export. The returned string should be compatible with the corresponding deserialize(String) implementation.
IJsonSerializer serializer = new IJsonSerializer() {
private final com.google.gson.Gson gson = new com.google.gson.Gson();
@Override
public String serialize(Object value) {
return gson.toJson(java.util.Collections.singletonMap("value", value));
}
@Override
public Object deserialize(String json) {
return gson.fromJson(json, java.util.Map.class);
}
};
String json = serializer.serialize("A");
value - The object to serialize. null handling is implementation-defined.Implement this method to reconstruct an application-specific object from its JSON representation. The concrete return type depends on the serializer implementation and how the JSON content is interpreted.
IJsonSerializer serializer = new IJsonSerializer() {
private final com.google.gson.Gson gson = new com.google.gson.Gson();
@Override
public String serialize(Object value) {
return gson.toJson(java.util.Collections.singletonMap("value", value));
}
@Override
public Object deserialize(String json) {
return gson.fromJson(json, java.util.Map.class);
}
};
Object value = serializer.deserialize("{\"value\":\"A\"}");
json - The JSON string to deserialize.