jakartaee / jsonp-api

Jakarta JSON Processing
https://eclipse.org/ee4j/jsonp
Other
140 stars 60 forks source link

Embrace more types on ObjectBuilder? Enable JSON-Schema linkage #103

Open rmannibucau opened 6 years ago

rmannibucau commented 6 years ago

JsonObjectBuilder is a very convenient API and has the advantage in current form to not loose immediately the format of the underlying data (BigDecimal/BigInteger, long, ....). However I think it should cover what developpers consider as "primitives". To be accurate I think we can use json schema specification as a basis.

What is missing IMO is:

The most important (and urgent) item is likely about the dates but longer term it would be very good to have an API allowing users or implementations to generate a schema from the builder API transparently (just decorating the default implementations).

keilw commented 6 years ago

I think there was a similar question about Date/Time. These types are not in the JSON standard (RFC) so while JSON-B provides out of the box mapping to certain types it does not seem covered by the standard. @m0mus WDYT about this?

rmannibucau commented 6 years ago

@keilw issue is not in jsongenerator or components like that but jsonobjectbuilder which is java first so jsonobjectbuilder should provide a stronger typing than json and lower level components IMHO.

keilw commented 6 years ago

@rmannibucau I'm talking about JsonObjectBuilder which is only creates a JsonObject right now. Do you suggest to add methods like JsonObjectBuilder add(String name, LocalDateTime value); or similar? Not sure, if this fits in a lower level API, but @m0mus has to say, how he feels it should evolve if any beyond the JSON specification. In that specification types like Date/Time (https://www.w3schools.com/js/js_json_datatypes.asp) are still unsupported. Since XML Schema is also used alongside JAXB primarily to bind new data types defined in that schema, I am not sure, if JSON Schema and this spec make sense together. It does feel very well suited for JSON-B.

rmannibucau commented 6 years ago

Well, the builder is an awesome api to

  1. Enrich the generation with meta (jsonschema)
  2. Create a JsonObject backed with another serialization like avro or protobuf

Only issue is it misses some type info so would be great to fill the gap to avoid another api on top of it

keilw commented 6 years ago

The thing is there IS another API on top of that JSON-B. I leave it to @m0mus what aspects to add or cover here, some I have the feeling belong to JSON-B, and it is up to users if they are happy with low-level functionality of the strict JSON standard or want a richer type-system.

rmannibucau commented 6 years ago

@keilw no, JSON-B doesnt overlap this use case at all, the opposite is true, enhacing jsonp to support that would benefit json-b but the opposite will not.

keilw commented 6 years ago

@m0mus WDYT, does it belong here or rather JSON-B?

Based on the intro example, it would be something like

 // Create Json and serialize
   JsonObject json = Json.createObjectBuilder()
     .add("name", "Falco")
     .add("age", BigDecimal.valueOf(3))
     **.add("dob", LocalDate.of(1957, 2, 19))**
     .add("biteable", Boolean.FALSE).build();
   String result = json.toString();
m0mus commented 6 years ago

I'm fine to add it to JSONP.