This project allows custom JSON key syntax
- KeyParse does not recursively search nested objects.
- Non-compliant keys are ignored by the KeyParse layer.
{
"key:[attr1:val1,attr2:val2]": "value"
}Deserialize the JSON normally with Jackson:
ObjectMappermapper = newObjectMapper();
ObjectNoderoot =
(ObjectNode) mapper.readTree(json);
//Create a reader for the current object:JacksonJsonKeyReaderreader =
JacksonJsonKeyReader.of(root);
//Then request attributes for a logical key:Optional<Map<String, String>> attributes =
reader.attributes("product");For:
{
"product:[type:card,id:123]": "GD01-001"
}attributes.ifPresent(attrs -> { Stringtype = attrs.get("type");
Stringid = attrs.get("id");
System.out.println(type);
System.out.println(id); });the returned attributes are:
type = card id = 123