ObjectMapper
Code IndexAdd Codota to your IDE (free)

Best code snippets using com.fasterxml.jackson.databind.ObjectMapper(Showing top 20 results out of 13,842)

Refine search

  • ObjectMapperSingleton
  • JmesPathExpression
  • JmesPathEvaluationVisitor
  • AcceptorPathMatcher
  • ObjectNode
  • JsonNode
  • ArrayNode
  • Common ways to obtain ObjectMapper
private void myMethod () {
ObjectMapper o =
  • new ObjectMapper()
  • Smart code suggestions by Codota
}
origin: prestodb/presto

private boolean isAccumuloView(byte[] data)
    throws IOException
{
  // AccumuloView contains a 'data' node
  return mapper.reader().readTree(new String(data)).has("data");
}
origin: stackoverflow.com

 final String json = "{\"objects\" : [\"One\", \"Two\", \"Three\"]}";

final JsonNode arrNode = new ObjectMapper().readTree(json).get("objects");
if (arrNode.isArray()) {
  for (final JsonNode objNode : arrNode) {
    System.out.println(objNode);
  }
}
origin: swagger-api/swagger-core

private static void apply(Object objectToSerialize, String str, ObjectMapper mapper) {
  final ObjectNode lhs = mapper.convertValue(objectToSerialize, ObjectNode.class);
  ObjectNode rhs = null;
  try {
    rhs = mapper.readValue(str, ObjectNode.class);
  } catch (IOException e) {
    LOGGER.error("Failed to read value", e);
  }
  if (!lhs.equals(new ObjectNodeComparator(), rhs)) {
    fail(String.format("Serialized object:\n%s\ndoes not equal to expected serialized string:\n%s", lhs, rhs));
  }
}
origin: Activiti/Activiti

public static void convertSignalDefinitionsToJson(BpmnModel bpmnModel, ObjectNode propertiesNode) {
 if (bpmnModel.getSignals() != null) {
  ArrayNode signalDefinitions = objectMapper.createArrayNode();
  for (Signal signal : bpmnModel.getSignals()) {
   ObjectNode signalNode = signalDefinitions.addObject();
   signalNode.put(PROPERTY_SIGNAL_DEFINITION_ID, signal.getId());
   signalNode.put(PROPERTY_SIGNAL_DEFINITION_NAME, signal.getName());
   signalNode.put(PROPERTY_SIGNAL_DEFINITION_SCOPE, signal.getScope());
  }
  propertiesNode.set(PROPERTY_SIGNAL_DEFINITIONS, signalDefinitions);
 }
}

origin: Activiti/Activiti

public static void convertMessagesToJson(BpmnModel bpmnModel, ObjectNode propertiesNode) {
 if (bpmnModel.getMessages() != null) {
  ArrayNode messageDefinitions = objectMapper.createArrayNode();
  for (Message message : bpmnModel.getMessages()) {
   ObjectNode messageNode = messageDefinitions.addObject();
   messageNode.put(PROPERTY_MESSAGE_DEFINITION_ID, message.getId());
   messageNode.put(PROPERTY_MESSAGE_DEFINITION_NAME, message.getName());
  }
  propertiesNode.set(PROPERTY_MESSAGE_DEFINITIONS, messageDefinitions);
 }
}

origin: joelittlejohn/jsonschema2pojo

private ObjectNode objectSchema(JsonNode exampleObject) {
  ObjectNode schema = this.objectMapper.createObjectNode();
  schema.put("type", "object");
  ObjectNode properties = this.objectMapper.createObjectNode();
  for (Iterator<String> iter = exampleObject.fieldNames(); iter.hasNext();) {
    String property = iter.next();
    properties.set(property, schemaFromExample(exampleObject.get(property)));
  }
  schema.set("properties", properties);
  return schema;
}
origin: joelittlejohn/jsonschema2pojo

private JsonNode mergeArrayItems(JsonNode exampleArray) {
  ObjectNode mergedItems = this.objectMapper.createObjectNode();
  for (JsonNode item : exampleArray) {
    if (item.isObject()) {
      mergeObjectNodes(mergedItems, (ObjectNode) item);
    }
  }
  return mergedItems;
}
origin: Vedenin/useful-java-links

/**
 *  Example to readJson using TreeModel
 */
private static void readJson() throws IOException {
  ObjectMapper mapper = new ObjectMapper();
  JsonNode rootNode = mapper.readValue("{\"message\":\"Hi\",\"place\":{\"name\":\"World!\"}}", JsonNode.class);
  String message = rootNode.get("message").asText(); // get property message
  JsonNode childNode =  rootNode.get("place"); // get object Place
  String place = childNode.get("name").asText(); // get property name
  System.out.println(message + " " + place); // print "Hi World!"
}
origin: Activiti/Activiti

public static ObjectNode createPositionNode(double x, double y) {
 ObjectNode positionNode = objectMapper.createObjectNode();
 positionNode.put(EDITOR_BOUNDS_X, x);
 positionNode.put(EDITOR_BOUNDS_Y, y);
 return positionNode;
}

origin: swagger-api/swagger-core

  @Override
  public Response deserialize(JsonParser jp, DeserializationContext ctxt)
      throws IOException {
    JsonNode node = jp.getCodec().readTree(jp);
    JsonNode sub = node.get("$ref");

    if (sub != null) {
      return Json.mapper().convertValue(node, RefResponse.class);
    } else {
      Response response = Json.responseMapper().convertValue(node, Response.class);
      return response;
    }
  }
}
origin: Activiti/Activiti

protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
 BoundaryEvent boundaryEvent = (BoundaryEvent) baseElement;
 ArrayNode dockersArrayNode = objectMapper.createArrayNode();
 ObjectNode dockNode = objectMapper.createObjectNode();
 GraphicInfo graphicInfo = model.getGraphicInfo(boundaryEvent.getId());
 GraphicInfo parentGraphicInfo = model.getGraphicInfo(boundaryEvent.getAttachedToRef().getId());
 dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX() - parentGraphicInfo.getX());
 dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY() - parentGraphicInfo.getY());
 dockersArrayNode.add(dockNode);
 flowElementNode.set("dockers", dockersArrayNode);
 propertiesNode.put(PROPERTY_CANCEL_ACTIVITY, boundaryEvent.isCancelActivity());
 addEventProperties(boundaryEvent, propertiesNode);
}
origin: org.apache.logging.log4j/log4j-core

@Test
public void gelfLayout() throws IOException {
  final Logger logger = context.getLogger();
  logger.info("Message");
  final String gelf = context.getListAppender("list").getMessages().get(0);
  final ObjectMapper mapper = new ObjectMapper();
  final JsonNode json = mapper.readTree(gelf);
  assertEquals("Message", json.get("short_message").asText());
  assertEquals("myhost", json.get("host").asText());
  assertEquals("FOO", json.get("_foo").asText());
  assertEquals(new JavaLookup().getRuntime(), json.get("_runtime").asText());
}
origin: Graylog2/graylog2-server

  public static Optional<AbsoluteRange> extractHistogramBoundaries(final String query) {
    try {
      final JsonParser jp = OBJECT_MAPPER.getFactory().createParser(query);
      final JsonNode rootNode = OBJECT_MAPPER.readTree(jp);
      final JsonNode timestampNode = rootNode.findValue("range").findValue("timestamp");
      final String from = elasticSearchTimeFormatToISO8601(timestampNode.findValue("from").asText());
      final String to = elasticSearchTimeFormatToISO8601(timestampNode.findValue("to").asText());

      return Optional.of(AbsoluteRange.create(from, to));
    } catch (Exception ignored) {
      return Optional.empty();
    }
  }
}
origin: Activiti/Activiti

public static JsonNode validateIfNodeIsTextual(JsonNode node) {
 if (node != null && !node.isNull() && node.isTextual() && StringUtils.isNotEmpty(node.asText())) {
  try {
   node = validateIfNodeIsTextual(objectMapper.readTree(node.asText()));
  } catch(Exception e) {
   logger.error("Error converting textual node", e);
  }
 }
 return node;
}

origin: swagger-api/swagger-core

private static Map<String, Object> getVendorExtensions(JsonNode node) {
  Map<String, Object> result = new HashMap<String, Object>();
  Iterator<String> fieldNameIter = node.fieldNames();
  while (fieldNameIter.hasNext()) {
    String fieldName = fieldNameIter.next();
    if(fieldName.startsWith("x-")) {
      JsonNode extensionField = node.get(fieldName);
      Object extensionObject = Json.mapper().convertValue(extensionField, Object.class);
      result.put(fieldName, extensionObject);
    }
  }
  return result;
}
origin: Activiti/Activiti

public static ObjectNode createResourceNode(String id) {
 ObjectNode resourceNode = objectMapper.createObjectNode();
 resourceNode.put(EDITOR_SHAPE_ID, id);
 return resourceNode;
}

origin: Activiti/Activiti

protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
 SubProcess subProcess = (SubProcess) baseElement;
 propertiesNode.put("activitytype", "Event-Sub-Process");
 propertiesNode.put("subprocesstype", "Embedded");
 ArrayNode subProcessShapesArrayNode = objectMapper.createArrayNode();
 GraphicInfo graphicInfo = model.getGraphicInfo(subProcess.getId());
 processor.processFlowElements(subProcess, model, subProcessShapesArrayNode, formKeyMap, 
   decisionTableKeyMap, graphicInfo.getX(), graphicInfo.getY());
 flowElementNode.set("childShapes", subProcessShapesArrayNode);
}
origin: Activiti/Activiti

public static void convertMessagesToJson(Collection<Message> messages, ObjectNode propertiesNode) {
 String propertyName = "messages";
 ArrayNode messagesNode = objectMapper.createArrayNode();
 for (Message message : messages) {
  ObjectNode propertyItemNode = objectMapper.createObjectNode();
  propertyItemNode.put(PROPERTY_MESSAGE_ID, message.getId());
  propertyItemNode.put(PROPERTY_MESSAGE_NAME, message.getName());
  propertyItemNode.put(PROPERTY_MESSAGE_ITEM_REF, message.getItemRef());
  messagesNode.add(propertyItemNode);
 }
 propertiesNode.set(propertyName, messagesNode);
}
origin: Vedenin/useful-java-links

public  static void main(String[] args) throws IOException {
  ObjectMapper mapper = new ObjectMapper();
  JsonNode root = mapper.readTree(json);
  String author = root.at("/store/book/3/title").asText();
  System.out.println(author); // print ["Hello, Middle-earth! "]
  System.out.println();
  String jsonHiWorld = "{\"message\":\"Hi\",\"place\":{\"name\":\"World!\"}}\"";
  String message = mapper.readTree(jsonHiWorld).at("/message").asText();
  String place = mapper.readTree(jsonHiWorld).at("/place/name").asText();
  System.out.println(message + " " + place); // print "Hi World!"
}
origin: joelittlejohn/jsonschema2pojo

private ObjectNode arraySchema(JsonNode exampleArray) {
  ObjectNode schema = this.objectMapper.createObjectNode();
  schema.put("type", "array");
  if (exampleArray.size() > 0) {
    JsonNode exampleItem = exampleArray.get(0).isObject() ? mergeArrayItems(exampleArray) : exampleArray.get(0);
    schema.set("items", schemaFromExample(exampleItem));
  }
  return schema;
}
com.fasterxml.jackson.databindObjectMapper

Javadoc

This mapper (or, data binder, or codec) provides functionality for converting between Java objects (instances of JDK provided core classes, beans), and matching JSON constructs. It will use instances of JsonParser and JsonGeneratorfor implementing actual reading/writing of JSON.

The main conversion API is defined in ObjectCodec, so that implementation details of this class need not be exposed to streaming parser and generator classes.

Note on caching: root-level deserializers are always cached, and accessed using full (generics-aware) type information. This is different from caching of referenced types, which is more limited and is done only for a subset of all deserializer types. The main reason for difference is that at root-level there is no incoming reference (and hence no referencing property, no referral information or annotations to produce differing deserializers), and that the performance impact greatest at root level (since it'll essentially cache the full graph of deserializers involved).

Most used methods

  • <init>
    Copy-constructor, mostly used to support #copy.
  • readValue
  • writeValueAsString
    Method that can be used to serialize any Java value as a String. Functionally equivalent to calling
  • readTree
    Method to deserialize JSON content as tree expressed using set of JsonNode instances. Returns root o
  • configure
    Method for changing state of an on/off serialization feature for this object mapper.
  • registerModule
    Method for registering a module that can extend functionality provided by this mapper; for example,
  • writeValue
    Method that can be used to serialize any Java value as JSON output, using Writer provided. Note: met
  • writeValueAsBytes
    Method that can be used to serialize any Java value as a byte array. Functionally equivalent to call
  • setSerializationInclusion
    Convenience method, equivalent to calling: setPropertyInclusion(JsonInclude.Value.construct(incl, i
  • convertValue
    Convenience method for doing two-step conversion from given value, into instance of given value type
  • writer
    Factory method for constructing ObjectWriter that will serialize objects using specified DateFormat;
  • createObjectNode
    Note: return type is co-variant, as basic ObjectCodec abstraction cannot refer to concrete node typ
  • writer,
  • createObjectNode,
  • writerWithDefaultPrettyPrinter,
  • getTypeFactory,
  • enable,
  • getFactory,
  • reader,
  • valueToTree,
  • treeToValue,
  • disable

Popular classes and methods

  • runOnUiThread (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • getExternalFilesDir (Context)
  • GridBagLayout (java.awt)
  • BigDecimal (java.math)
    An immutable arbitrary-precision signed decimal.A value is represented by an arbitrary-precision "un
  • ResultSet (java.sql)
    A table of data representing a database result set, which is usually generated by executing a statem
  • Format (java.text)
    Format is an abstract base class for formatting locale-sensitive information such as dates, messages
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t

For IntelliJ IDEA,
Android Studio or Eclipse

  • Codota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutContact Us
  • Terms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)