eclipse-ee4j / eclipse-ee4j/yasson

Map deserialization doesn't use Adapter and generates runtime exception on access

Open
#253 3 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Java
Stars
218
Forks
109
Avg merge
1d 5h
Merged PRs (30d)
9

Description

Given a simple POJO "Person" with a String attribute "name" and a test like

` public static void main(String[] args) {
String json = "{\"foo\" : \"bar\"}";
Map map = JsonbBuilder.create().fromJson(json, new HashMap() {}.getClass().getGenericSuperclass());
map.keySet().forEach(Person::getName);
}
`

I end up with
`Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to test.Person
at java.util.HashMap$KeySet.forEach(HashMap.java:933)
at test.Test.main(Test.java:14)`

If I register an adapter for Person, it is never called. How can a String even fit into the Person map key and only be detected at runtime?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.