IBM / JSONata4Java

Open Source Java version of JSONata
Apache License 2.0
90 stars 37 forks source link

Support for other JSON libraries #262

Open FeldrinH opened 1 year ago

FeldrinH commented 1 year ago

It seems that it is currently only possible to pass JSON in and get JSON out as Jackson JsonNode. It would be nice if it was possible to use JSON representations from other libraries as well, such as Gson's JsonElement.

wnm3 commented 1 year ago

This could be accomplished by a shim that gets the String from one form and parses into the other... not sure if this should be done in this library of as an external wrapper using something like this:

import com.fasterxml.jackson.databind.JsonNode;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;

static ObjectMapper _objectMapper = new ObjectMapper();

public static class GSONConverter {
   static public JsonElement toGSON(JsonNode node) throws Exception {
      return JsonParser.parseString(_objectMapper.writeValueAsString(node));
   }
}