How to manipulate a JSON with fasterXML in java?

0

I have a json that comes from the MongoDB bank, I have to get and manipulate json using fasterXml. I will have to get the json properties names and separate them with period (.) Instead of comma (,)

Type like this:

"type" : "object",
  "id" : "urn:jsonschema:com",
  "properties" : {
    "id" : {
      "type" : "any"
    },
    "name" : {
      "type" : "string"
    },
    "version" : {
      "type" : "string"
    },
    "code" : {
      "type" : "string"
    },
    "clazz" : {
      "type" : "string"
    }
  }
}

And show like this:

properties{id.name.version.code.clazz};

Show everything you have inside the parent that is "properties", or something like that !!

    
asked by anonymous 01.02.2016 / 20:03

1 answer

0

In my I am using log to show instead of sysout

ObjectMapper mapper = new ObjectMapper();

List<String> node = new ArrayList<>();          
JsonNode objectRoot = mapper.readTree(code);
Iterator<String> fields = objectRoot.fieldNames();
String field = "";
while(fields.hasNext()) {
    field = fields.next();

    node.add(field);
}
LOGGER.info("GRAU I: "+ field);

JsonNode arrayRoot = mapper.readTree(code);

Iterator<JsonNode> elements = arrayRoot.elements();

JsonNode element;

while(elements.hasNext()) {
    element = elements.next(); 
    field = "";
    fields = element.fieldNames();

    while(fields.hasNext()){
        field = fields.next();

        node.add(field);

        LOGGER.info("GRAU II em diante: "+ field);
    }

    return node;

}

I think that's it

    
05.02.2016 / 14:52