We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Changing the order of the fields in a Java Bean changes the behaviour of JsonbAdapter.
JsonbAdapter
Given the JsonbAdapter :
public class FirstNameAdapter implements JsonbAdapter<String, JsonValue> { @Override public JsonValue adaptToJson(String firstName) { return Json.createValue(firstName.subSequence(0,1).toString()); } @Override public String adaptFromJson(JsonValue json) { return json.toString(); } }
And the Java Bean:
public class Author { @JsonbTypeAdapter(FirstNameAdapter.class) private String firstName; private String lastName; // plumbing code omitted }
The adaptToJson() method is called twice, once for the firstName field and again for the lastName field. Change the order of the fields as follows:
adaptToJson()
firstName
lastName
public class Author { private String lastName; @JsonbTypeAdapter(FirstNameAdapter.class) private String firstName; // plumbing code omitted }
and only the firstName field is passed to the adaptToJson() method.
Code is here: https://github.com/readlearncode/Java-EE-8-Sampler/tree/master/json-b-1-0/src/main/java/com/readlearncode/devWorks/part2/adaptors
Unit tests here: https://github.com/readlearncode/Java-EE-8-Sampler/tree/master/json-b-1-0/src/test/java/com/readlearncode/devWorks/part2/adapter
The text was updated successfully, but these errors were encountered:
c835156
No branches or pull requests
Changing the order of the fields in a Java Bean changes the behaviour of
JsonbAdapter
.Given the
JsonbAdapter
:And the Java Bean:
The
adaptToJson()
method is called twice, once for thefirstName
field and again for thelastName
field. Change the order of the fields as follows:and only the
firstName
field is passed to theadaptToJson()
method.Code is here: https://github.com/readlearncode/Java-EE-8-Sampler/tree/master/json-b-1-0/src/main/java/com/readlearncode/devWorks/part2/adaptors
Unit tests here: https://github.com/readlearncode/Java-EE-8-Sampler/tree/master/json-b-1-0/src/test/java/com/readlearncode/devWorks/part2/adapter
The text was updated successfully, but these errors were encountered: