-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How is this different from JEE7 javax.json? #51
Comments
@moghaddam Commented The API you mentioned is the Java API for JSON Processing or JSON-P. It's a more low level API that is mostly used to parse the JSON file. The Java API for JSON Binding or JSON-B is a more higher level api which is used to serialize/deserialize an object into/from JSON format. You can use it to convert a POJO to a JSON string or deserialize a JSON string into a POJO. As an example the reference implementation of the JSON-B (Yasson) uses JSON-P internally to generate the JSON output based on given input object and vice versa. Regards |
@amihaiemil Commented |
@moghaddam Commented |
@amihaiemil Commented |
@amihaiemil Commented /**
* Student from XML.
*/
public XmlStudent implements Student {
private XML student;
//ctors
@Override
@JsonbProperty
public String firstName() {
return this.student.getElement("firstName");
}
@Override
@JsonbProperty
public String lastName() {
return this.student.getElement("lastName");
}
//....
} So I would like it to work without getters and setters, no dumb POJOs. As I understand from this example, Please, tell me it isn't so :(( |
@amihaiemil Commented If we drop the POJO concept, which we should, I think most things can be done with JSON-P :) |
@moghaddam Commented Also regarding your complains about POJOs, if you want to use your POJO just as a placeholder to keep your data and there is no other business in it, then you don't have to define getter/setter methods. It would be enough to just define your properties as public. All APIs mentioned above work perfectly with a POJO with public members and can easily serialize/deserialize them. |
@amihaiemil Commented I am not interested in creating objects from Json. You can have a JsonObject behind an object just fine. String -> JsonObject and then encapsulate that and read from it. I am interested in creating Json from objects. Real objects, not data holders with String attributes. My object may take data from an Http endpoint (it would encapsulate an http request) and I want Yasson to parse it via that annotation. No ''get'' prefix either. It would really be a step forward towards cleaner OOP. |
@amihaiemil Commented |
@grimly Commented For you get/setterphobia you could take a look at Lombok, it helps a lot at completing the useless code you never want to write. |
@aguibert Commented public class Student {
public String firstName;
public String lastName;
} And then you could deserialize the object like this: Jsonb jsonb = JsonbProvider.provider().create.().build();
Student s = jsonb.fromJson(new FileReader("inputs/student.json"), Student.class); IMO this is a significant improvement over the JSON-P API which can basically only turn JSON data into a glorified Map. Being able to go a step further and get the JSON data into a proper POJO is convenient. |
@amihaiemil Commented Instead, objects should be "live", they should animate the data they have behind, not be the data. Student s = new JsonStudent(
Json.createReader(new FileReader(...)).readObject()
); However, JSON-P cannot turn Object into Json, and this is why I opened this issue. I would like JSON-B to be able to do that without the POJO concept. Jackson does it just fine, with annotations. Here is a live ElasticSearchResult, which can also be turned into Json thanks to Jackson (SearchResult interface is annotated). Now, of course, that JsonStudent of mine is not much different from a POJO, but it can be wrapped in decorators and be enriched with functionality. I wrote about it in detail here: http://www.amihaiemil.com/2017/09/01/data-should-be-animated-not-represented.html |
@amihaiemil Commented I would like to annotate an object's accessor methods with |
@gembin Commented |
|
There already is a Json api from jee7. What is new in this one, why couldn't the implementation be done based on that API?
Many devs already don't understand how to handle Json in Java. You see a lot of mess, apps using both the standard api and gson from Google or other libs. I really don't see the use for a new one -- but, again, I may be missing something.
The text was updated successfully, but these errors were encountered: