Skip to content

Problem writing "empty" Map key (String with length 0) #30

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

Closed
cowtowncoder opened this issue Dec 9, 2015 · 2 comments
Closed

Problem writing "empty" Map key (String with length 0) #30

cowtowncoder opened this issue Dec 9, 2015 · 2 comments
Milestone

Comments

@cowtowncoder
Copy link
Member

(problem reported by user via email)


Smile reader doesn’t do well with a map with an empty String key.

Map map = new HashMap();
map.put("foo", Collections.singletonMap("", "bar"));
ObjectMapper smileMapper = new ObjectMapper(new SmileFactory());
byte[] bytes = smileMapper.writer().writeValueAsBytes(map);
smileMapper.reader().readTree(new ByteArrayInputStream(bytes));

I get this exception:
Exception in thread "main" com.fasterxml.jackson.core.JsonParseException: Invalid shared name reference 2; only got 1 names in buffer (invalid content)
at [Source: java.io.ByteArrayInputStream@30c7da1e; line: -1, column: 12]


@cowtowncoder
Copy link
Member Author

Interesting... looks like a regression; test passes with 2.5, but fails with 2.6(.4).

@cowtowncoder cowtowncoder added this to the 2.6.5 milestone Dec 10, 2015
@cowtowncoder
Copy link
Member Author

So this is a regression from 2.5, due to rewrite of nextFieldName() method; it does not update state properly for the case of empty String (which has its dedicated token byte, separate from others).

The reason it had gone undetected is probably because:

  1. Use of empty String as JSON Object key is not very common AND
  2. This only caused problems with nextFieldName() but NOT with nextToken().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant