Package org.codehaus.jackson.map

Examples of org.codehaus.jackson.map.ObjectMapper.readTree()


    final ObjectMapper mapper = new ObjectMapper();
    final JsonParser parser = new JsonFactory().createJsonParser(json)
        .enable(Feature.ALLOW_COMMENTS)
        .enable(Feature.ALLOW_SINGLE_QUOTES)
        .enable(Feature.ALLOW_UNQUOTED_FIELD_NAMES);
    final JsonNode root = mapper.readTree(parser);
    return fromJsonNode(root, schema);
  }

  /**
   * Instantiates a specific record by name.
View Full Code Here


        }

        JsonNode result;
        try {
            ObjectMapper mapper = new ObjectMapper();
            result = mapper.readTree(jsonContent);
        } catch (Exception e) {
            throw new RuntimeException(String.format("Error trying to parse json response from url %s, got: %s",
                    url, jsonContent), e);
        }
        return result;
View Full Code Here

    rootBody.setBody(body);

    if (body != null && body.length() != 0) {
      ObjectMapper mapper = new ObjectMapper();
      try {
        JsonNode root = mapper.readTree(ensureArrayFormat(body));

        Iterator<JsonNode> iterator = root.getElements();
        while (iterator.hasNext()) {
          JsonNode            node             = iterator.next();
          Map<String, Object> mapProperties    = new HashMap<String, Object>();
View Full Code Here

   * @return a node tree
   * @throws IOException on any parsing problems
   */
  public static ContainerNode parse(String json) throws IOException {
    ObjectMapper mapper = new ObjectMapper(factory);
    JsonNode jsonNode = mapper.readTree(json);
    if (!(jsonNode instanceof ContainerNode)) {
      throw new IOException("Wrong JSON data: " + json);
    }
    return (ContainerNode) jsonNode;
  }
View Full Code Here

  public StatePair deserialize(JsonParser parser,
                               DeserializationContext context)
  throws IOException, JsonProcessingException {
    ObjectMapper mapper = (ObjectMapper) parser.getCodec();
    // set the state-pair object tree
    ObjectNode statePairObject = (ObjectNode) mapper.readTree(parser);
    Class<?> stateClass = null;
   
    try {
      stateClass =
        Class.forName(statePairObject.get("className").getTextValue().trim());
View Full Code Here

    gatherJsonFiles(jsonFilesToValidate, artifactDir);
    ObjectMapper mapper = new ObjectMapper();
    for (File file : jsonFilesToValidate) {
      FileReader reader = new FileReader(file);
      try {
        mapper.readTree(reader);
      }
      catch (JsonProcessingException e) {
        warn("Error processing %s.", file.getAbsolutePath());
        throw e;
      }
View Full Code Here

            ObjectMapper mapper = new ObjectMapper();
            mapper.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, false);
            try {
                System.out.println("Setting with json");
                JsonNode node = mapper.readTree(args[0]);
                url = getUrl(node.get("url").getTextValue());
                dbName = node.get("db").getTextValue();
                recordingDocId = node.get("recording").getTextValue();
                user = node.get("user").getTextValue();
                System.out.println("Json reading complete");
View Full Code Here

        String result = (String)serializer.transform(fc);
        assertNotNull(result);
        // compare the structure and values but not the attributes' order
        ObjectMapper mapper = new ObjectMapper();
        JsonNode actualJsonNode = mapper.readTree(result);
        JsonNode expectedJsonNode = mapper.readTree(JsonBeanRoundTripTestCase.JSON_STRING);
        assertEquals(actualJsonNode, expectedJsonNode);

        FruitCollection result2 = (FruitCollection)deserializer.transform(result);
        assertNotNull(result2);
View Full Code Here

        String result = (String)serializer.transform(fc);
        assertNotNull(result);
        // compare the structure and values but not the attributes' order
        ObjectMapper mapper = new ObjectMapper();
        JsonNode actualJsonNode = mapper.readTree(result);
        JsonNode expectedJsonNode = mapper.readTree(JsonBeanRoundTripTestCase.JSON_STRING);
        assertEquals(actualJsonNode, expectedJsonNode);

        FruitCollection result2 = (FruitCollection)deserializer.transform(result);
        assertNotNull(result2);
        assertEquals(fc, result2);
View Full Code Here

            final InputStream configStream = configSource.getInputStream();
            buffer = toByteArray(configStream);
            configStream.close();
            final InputStream is = new ByteArrayInputStream(buffer);
            final ObjectMapper mapper = new ObjectMapper().configure(JsonParser.Feature.ALLOW_COMMENTS, true);
            root = mapper.readTree(is);
            if (root.size() == 1) {
                final Iterator<JsonNode> i = root.getElements();
                root = i.next();
            }
            processAttributes(rootNode, root);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.