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());
}
}
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());
}
}
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);
}
}
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();
}
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;
}
Aggregations