wanglingsong / JsonSurfer

A streaming JsonPath processor in Java
MIT License
292 stars 55 forks source link

Parsing maps/jackson #57

Closed drumcircle closed 5 years ago

drumcircle commented 5 years ago

In this document, metricValues is a Map<string,double>.

"metricValues": { "metric1": 10.977, "metric2": 0.062111801242236024 }

Variations of this expression:

Collection<Object> metricValues = surfer.collectAll(json, "$.body.metricValues.*");

Are pulling up the numbers (10.977) but not the keys ("metric1").

I've tried to cast to maps, classes with name-value, etc.

Suggestions?

wanglingsong commented 5 years ago

You can use this API to get current field name in JsonPathListener: https://github.com/jsurfer/JsonSurfer/blob/master/jsurfer-core/src/main/java/org/jsfr/json/ParsingContext.java#L65