jsonb-api icon indicating copy to clipboard operation
jsonb-api copied to clipboard

Way to map directly to/from JsonGenerator and JsonParser

Open jjspiegel opened this issue 6 years ago • 6 comments

Some data binding frameworks provide a way to do mappings to/from parsers and generator.

JAXB:

https://docs.oracle.com/javase/8/docs/api/javax/xml/bind/JAXB.html#unmarshal-javax.xml.transform.Source-java.lang.Class- https://docs.oracle.com/javase/8/docs/api/javax/xml/bind/JAXB.html#marshal-java.lang.Object-javax.xml.transform.Result-

(see StAXResult and StAXSource)

Jackson:

https://fasterxml.github.io/jackson-databind/javadoc/2.7/com/fasterxml/jackson/databind/ObjectMapper.html#writeValue(com.fasterxml.jackson.core.JsonGenerator,%20java.lang.Object) https://fasterxml.github.io/jackson-databind/javadoc/2.7/com/fasterxml/jackson/databind/ObjectMapper.html#readValues(com.fasterxml.jackson.core.JsonParser,%20java.lang.Class)

This is a useful feature as it allows a user to leverage the mapping rules without requiring a serialization format (JSON text or some other format). Also some implementations might only implement parser/generator and not implement JsonProvider.

Could we add to/from JSON methods for JsonParser and JsonGenerator?

See also: https://github.com/eclipse-ee4j/yasson/issues/245

jjspiegel avatar Feb 27 '19 19:02 jjspiegel

Closing this item as a duplicate of #111

aguibert avatar Jul 29 '19 15:07 aguibert

Based on the bug descriptions, these issues do not appear to be duplicates. Can you give an explanation or reopen this issue?

jjspiegel avatar Jul 29 '19 18:07 jjspiegel

I had closed it as a duplicate because #111 refers to a similar type of bridge methods w/ JSON-P. I figured to/fromJsonStructure would be sufficient for users to bridge with JSON-P.

I suppose bridge methods with JsonGenerator/Parser would also have value, so I can re-open this issue.

aguibert avatar Jul 30 '19 16:07 aguibert

See #224 for some discussion about why bridging to/from JsonStructure is insufficient. I missed this issue when I filed the new one, but @jjspiegel's original request is what I'm looking for as well.

emattheis avatar Mar 09 '20 19:03 emattheis

Also, note that some work is likely necessary in JSON-P to make this work like JAXB or Jackson: https://github.com/eclipse-ee4j/jsonp/issues/233

emattheis avatar Mar 09 '20 19:03 emattheis