Search in sources :

Example 21 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project jackson-databind by FasterXML.

the class ArrayNodeTest method testNullAdds.

public void testNullAdds() {
    JsonNodeFactory f = objectMapper().getNodeFactory();
    ArrayNode array = f.arrayNode(14);
    array.add((BigDecimal) null);
    array.add((BigInteger) null);
    array.add((Boolean) null);
    array.add((byte[]) null);
    array.add((Double) null);
    array.add((Float) null);
    array.add((Integer) null);
    array.add((JsonNode) null);
    array.add((Long) null);
    array.add((String) null);
    assertEquals(10, array.size());
    for (JsonNode node : array) {
        assertTrue(node.isNull());
    }
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 22 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project jackson-databind by FasterXML.

the class ArrayNodeTest method testNullInserts.

public void testNullInserts() {
    JsonNodeFactory f = objectMapper().getNodeFactory();
    ArrayNode array = f.arrayNode(3);
    array.insert(0, (BigDecimal) null);
    array.insert(0, (BigInteger) null);
    array.insert(0, (Boolean) null);
    // Offsets out of the range are fine; negative become 0;
    // super big just add at the end
    array.insert(-56, (byte[]) null);
    array.insert(0, (Double) null);
    array.insert(200, (Float) null);
    array.insert(0, (Integer) null);
    array.insert(1, (JsonNode) null);
    array.insert(array.size(), (Long) null);
    array.insert(1, (String) null);
    assertEquals(10, array.size());
    for (JsonNode node : array) {
        assertTrue(node.isNull());
    }
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 23 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project logging-log4j2 by apache.

the class ContextDataJsonAttributeConverter method convertToDatabaseColumn.

@Override
public String convertToDatabaseColumn(final ReadOnlyStringMap contextData) {
    if (contextData == null) {
        return null;
    }
    try {
        final JsonNodeFactory factory = OBJECT_MAPPER.getNodeFactory();
        final ObjectNode root = factory.objectNode();
        contextData.forEach(new BiConsumer<String, Object>() {

            @Override
            public void accept(final String key, final Object value) {
                // we will cheat here and write the toString of the Object... meh, but ok.
                root.put(key, String.valueOf(value));
            }
        });
        return OBJECT_MAPPER.writeValueAsString(root);
    } catch (final Exception e) {
        throw new PersistenceException("Failed to convert contextData to JSON string.", e);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PersistenceException(javax.persistence.PersistenceException) IOException(java.io.IOException) PersistenceException(javax.persistence.PersistenceException) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 24 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class InfoArchiveRestClient method getValidJsonRequestForExport.

private String getValidJsonRequestForExport(String exportConfigurationUri, List<SearchResult> searchResults) {
    JsonNodeFactory jsonNodeFactory = new ObjectMapper().getNodeFactory();
    ObjectNode root = jsonNodeFactory.objectNode();
    ArrayNode includedRows = jsonNodeFactory.arrayNode();
    for (SearchResult searchResult : searchResults) {
        for (Row row : searchResult.getRows()) {
            includedRows.add(row.getId());
        }
    }
    TextNode exportConfiguration = jsonNodeFactory.textNode(exportConfigurationUri);
    root.set("exportConfiguration", exportConfiguration);
    root.set("includedRows", includedRows);
    return root.toString();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 25 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project gravitee-management-rest-api by gravitee-io.

the class ApiService_StartTest method mockEvent.

private EventEntity mockEvent(EventType eventType) throws Exception {
    final JsonNodeFactory factory = JsonNodeFactory.instance;
    ObjectNode node = factory.objectNode();
    node.set("id", factory.textNode(API_ID));
    Map<String, String> properties = new HashMap<>();
    properties.put(Event.EventProperties.API_ID.getValue(), API_ID);
    properties.put(Event.EventProperties.USER.getValue(), USER_NAME);
    Api api = new Api();
    api.setId(API_ID);
    EventEntity event = new EventEntity();
    event.setType(eventType);
    event.setId(UUID.randomUUID().toString());
    event.setPayload(objectMapper.writeValueAsString(api));
    event.setCreatedAt(new Date());
    event.setUpdatedAt(event.getCreatedAt());
    event.setProperties(properties);
    return event;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) EventEntity(io.gravitee.management.model.EventEntity) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Aggregations

JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)35 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)28 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)17 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 IOException (java.io.IOException)5 Test (org.junit.Test)5 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)4 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)4 Gateway (com.sequenceiq.cloudbreak.domain.Gateway)4 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)4 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)4 HashSet (java.util.HashSet)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 EventEntity (io.gravitee.management.model.EventEntity)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 PersistenceException (javax.persistence.PersistenceException)2