use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project hadoop by apache.
the class TestJsonUtil method testGetXAttrFromJson.
@Test
public void testGetXAttrFromJson() throws IOException {
String jsonString = "{\"XAttrs\":[{\"name\":\"user.a1\",\"value\":\"0x313233\"}," + "{\"name\":\"user.a2\",\"value\":\"0x313131\"}]}";
ObjectReader reader = new ObjectMapper().readerFor(Map.class);
Map<?, ?> json = reader.readValue(jsonString);
// Get xattr: user.a2
byte[] value = JsonUtilClient.getXAttr(json, "user.a2");
Assert.assertArrayEquals(XAttrCodec.decodeValue("0x313131"), value);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project knime-core by knime.
the class SubnodeLayoutJSONEditorPage method isJSONValid.
/**
* @return true, if current JSON layout structure is valid
*/
protected boolean isJSONValid() {
ObjectMapper mapper = JSONLayoutPage.getConfiguredObjectMapper();
ObjectReader reader = mapper.readerForUpdating(new JSONLayoutPage());
try {
String json = isWindows() ? m_textArea.getText() : m_jsonDocument;
JSONLayoutPage page = reader.readValue(json);
m_documentNodeIDs.clear();
if (page.getRows() != null) {
for (JSONLayoutRow row : page.getRows()) {
populateDocumentNodeIDs(row);
}
compareNodeIDs();
}
return true;
} catch (IOException | NumberFormatException e) {
String errorMessage;
if (e instanceof JsonProcessingException) {
JsonProcessingException jsonException = (JsonProcessingException) e;
Throwable cause = null;
Throwable newCause = jsonException.getCause();
while (newCause instanceof JsonProcessingException) {
if (cause == newCause) {
break;
}
cause = newCause;
newCause = cause.getCause();
}
if (cause instanceof JsonProcessingException) {
jsonException = (JsonProcessingException) cause;
}
errorMessage = jsonException.getOriginalMessage().split("\n")[0];
JsonLocation location = jsonException.getLocation();
if (location != null) {
errorMessage += " at line: " + (location.getLineNr() + 1) + " column: " + location.getColumnNr();
}
} else {
String message = e.getMessage();
errorMessage = message;
}
if (m_statusLine != null && !m_statusLine.isDisposed()) {
m_statusLine.setForeground(new Color(Display.getCurrent(), 255, 0, 0));
m_statusLine.setText(errorMessage);
int textWidth = isWindows() ? m_textArea.getSize().width : m_text.getSize().x;
Point newSize = m_statusLine.computeSize(textWidth, m_statusLine.getSize().y, true);
m_statusLine.setSize(newSize);
}
}
return false;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project data-prep by Talend.
the class MixedContentMapTest method testRead.
@Test
public void testRead() throws Exception {
final ObjectReader reader = mapper.reader(MixedContentMap.class);
final MixedContentMap map = reader.readValue(MixedContentMapTest.class.getResourceAsStream("mixedMapContent.json"));
assertThat(map, notNullValue());
assertThat(map.get("string"), is("string value"));
assertThat(map.get("numeric"), is("10"));
assertThat(map.get("boolean"), is("true"));
assertThat(map.get("double"), is("10.1"));
assertThat(map.get("null"), nullValue());
assertThat(map.get("empty"), is(""));
final String object = map.get("object");
assertThat(object, sameJSONAs("{\"eq\": { \"field\": \"nbCommands\",\"value\": \"13\" }}"));
final String array = map.get("array");
assertThat(array, sameJSONAs("[1, 2, 3]"));
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project keycloak by keycloak.
the class Serialization method from.
public static <T> T from(T orig, T target) {
if (orig == null) {
return null;
}
@SuppressWarnings("unchecked") final Class<T> origClass = (Class<T>) orig.getClass();
// Naive solution but will do.
try {
ObjectReader reader = MAPPER.readerForUpdating(target);
ObjectWriter writer = WRITERS.computeIfAbsent(origClass, MAPPER::writerFor);
final T res;
res = reader.readValue(writer.writeValueAsBytes(orig));
if (res != target) {
throw new IllegalStateException("Should clone into desired target");
}
return res;
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project components by Talend.
the class AbstractSpringIntegrationTests method buildTestDataSetFormData.
protected UiSpecsPropertiesDto buildTestDataSetFormData() throws java.io.IOException {
UiSpecsPropertiesDto formDataContainer = new UiSpecsPropertiesDto();
ObjectReader reader = mapper.readerFor(ObjectNode.class);
formDataContainer.setDependencies(singletonList(reader.readValue(TEST_DATA_STORE_PROPERTIES)));
formDataContainer.setProperties(reader.readValue(TEST_DATA_SET_PROPERTIES));
return formDataContainer;
}
Aggregations