boonproject / boon

Simple opinionated Java for the novice to expert level Java Programmer. Low Ceremony. High Productivity.
http://richardhightower.github.io/site/Boon/Welcome.html
Apache License 2.0
520 stars 102 forks source link

Escape HashMap Issue #335

Closed saschaarthur closed 4 years ago

saschaarthur commented 9 years ago

Escape for hashmap is not working properly:

Heres code as proof:

HashMap list = new HashMap<String,String>();
list.put("\"test\"", "\"test\"");

JsonSerializerFactory jsonSerializerFactory = new JsonSerializerFactory()
.useFieldsFirst()
.includeEmpty().includeNulls().includeDefaultValues();

JsonParserFactory jsonParserFactory = new JsonParserFactory()
.useFieldsOnly()
.lax();

ObjectMapper mapper = JsonFactory.create(jsonParserFactory, jsonSerializerFactory);

System.out.println(mapper.toJson(list));

this gives following invalid json (key is not escaped!):

{""test"":"\"test\""}
Mythobeast commented 8 years ago

I have also run into this problem, resulting in faulty JSON

RichardHightower commented 8 years ago

I agree. I don't escape keys by default. It can be enabled. And by that I mean, there should be code to enable this feature.