Add Serializable / DeSerializable support to JsonValues instead of pre-defined list

Hi!

I was just thinking about storing other stuff than simple String in JsonDocument, like CountryCodes from a java enum when… Unsupported type for JsonObject: CountryCode

So, why not using a serializer/deserializer logic in JsonValues ?

I’m thinking about something like
myJsonObject.put(“key”, myObject);
myJsonObject.get"key", myObject.getClass);

What are you thinking about this ?

Hi @cambierr,

well the JsonDocument and its corresponding JsonObject was meant to only accept those kinds of values which can be 1:1 represented in JSON.

What you want is more likely to entity mapping, and we’ll get experimental support for that in 2.2. By now, I think your best bet if you want to be very flexible is to use something like Jackson or GSON and then use the RawJsonDocument and feed the encoded json string (and decode the same way).

Iff you/we find a way to add those kinds of codec logic for JsonObjects/JsonArrays without much overhead, I’m open to adding it (but really only if it doesn’t make things too complicated).

cc @simonbasle

Hi @simonbasle,

I was thinking about something like:

public interface JsonValueTranscoder{
    public String toJsonValue(Object _input);
    public Object fromJsonValue(String _input);
} 

and then for using it, myJsonObject.put(“key”, myObject, myTranscoder)
or myJsonObject.get(“key”, myTranscoder);

This seems to be (at least, i think) the most simple and general approach for this problem.

If it seems good, I can write a sample and see how well it could be used ?