Fix #609: Reject a JSON array or object where a value is expected

When the parser was not at an event expected for the type to
deserialize, PositionChecker advanced it by one event, which is meant
for user-defined deserializers that leave the parser before the value.
For a JSON array or object it entered the container instead: a JSON
array bound to a String or Integer property was read as its first
element, the remaining elements were then taken as further values of
the enclosing object, and the last one won. An array of objects bound
to an object property was read the same way. Yasson 2 rejected these
documents.

Do not advance into an array or an object that is not expected, so such
a document is rejected with a JsonbException naming the property and
its type.

Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
2 files changed
tree: c35d074fdf26868a1cf4fd8edecd369c5c217359
  1. .github/
  2. etc/
  3. src/
  4. yasson-jmh/
  5. yasson-tck/
  6. .gitignore
  7. CONTRIBUTING.md
  8. LICENSE.md
  9. NOTICE.md
  10. pom.xml
  11. README.md
README.md

Eclipse Yasson

Maven Central

Gitter Javadocs Build Status License

Yasson is a Java framework which provides a standard binding layer between Java classes and JSON documents. This is similar to what JAXB is doing in the XML world. Yasson is an official reference implementation of JSON Binding (JSR-367).

It defines a default mapping algorithm for converting existing Java classes to JSON suitable for the most cases:

Jsonb jsonb = JsonbBuilder.create();
String result = jsonb.toJson(someObject);

For whom it's not enough it provides rich customization abilities through a set of annotations and rich programmatic API:

// Create custom configuration
JsonbConfig config = new JsonbConfig()
  .withNullValues(true)
  .withFormatting(true);

// Create Jsonb with custom configuration
Jsonb jsonb = JsonbBuilder.create(config);

// Use it!
String result = jsonb.toJson(someObject);

Questions?

Something not working right? Have an idea for an enhancement? Get in touch with the Yasson community in the following ways:

  • Gitter: a free instant-messaging platform (similar to Slack) that anyone can join.
  • Stackoverflow: As a question tagged [jsonb-api] and [yasson]
  • Github Issues: Open issues for enhancement ideas or bug reports

Licenses

Links