use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project jackson-databind by FasterXML.
the class TestInferredMutators method testDeserializationInference.
// for #195
public void testDeserializationInference() throws Exception {
final String JSON = "{\"x\":2}";
ObjectMapper mapper = new ObjectMapper();
// First: default case, inference enabled:
assertTrue(mapper.isEnabled(MapperFeature.INFER_PROPERTY_MUTATORS));
Point p = mapper.readValue(JSON, Point.class);
assertEquals(2, p.x);
// but without it, should fail:
mapper = new ObjectMapper();
mapper.disable(MapperFeature.INFER_PROPERTY_MUTATORS);
try {
p = mapper.readValue(JSON, Point.class);
fail("Should not succeeed");
} catch (JsonMappingException e) {
verifyException(e, "unrecognized field \"x\"");
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project hadoop by apache.
the class JobSubmitter method readTokensFromFiles.
@SuppressWarnings("unchecked")
private void readTokensFromFiles(Configuration conf, Credentials credentials) throws IOException {
// add tokens and secrets coming from a token storage file
String binaryTokenFilename = conf.get(MRJobConfig.MAPREDUCE_JOB_CREDENTIALS_BINARY);
if (binaryTokenFilename != null) {
Credentials binary = Credentials.readTokenStorageFile(FileSystem.getLocal(conf).makeQualified(new Path(binaryTokenFilename)), conf);
credentials.addAll(binary);
}
// add secret keys coming from a json file
String tokensFileName = conf.get("mapreduce.job.credentials.json");
if (tokensFileName != null) {
LOG.info("loading user's secret keys from " + tokensFileName);
String localFileName = new Path(tokensFileName).toUri().getPath();
try {
// read JSON
Map<String, String> nm = READER.readValue(new File(localFileName));
for (Map.Entry<String, String> ent : nm.entrySet()) {
credentials.addSecretKey(new Text(ent.getKey()), ent.getValue().getBytes(Charsets.UTF_8));
}
} catch (JsonMappingException | JsonParseException e) {
LOG.warn("couldn't parse Token Cache JSON file with user secret keys");
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project OpenAM by OpenRock.
the class ConditionTypesResource method jsonify.
/**
* Transforms a subclass of {@link EntitlementCondition} in to a JsonSchema representation.
* This schema is then combined with the Condition's name (taken as the resourceId) and all this is
* compiled together into a new {@link JsonValue} object until "title" and "config" fields respectively.
*
* @param conditionClass The class whose schema to produce.
* @param resourceId The ID of the resource to return
* @return A JsonValue containing the schema of the EntitlementCondition
*/
private JsonValue jsonify(Class<? extends EntitlementCondition> conditionClass, String resourceId, boolean logical) {
try {
final JsonSchema schema = mapper.generateJsonSchema(conditionClass);
//this will remove the 'name' attribute from those conditions which incorporate it unnecessarily
final JsonNode node = schema.getSchemaNode().get("properties");
if (node instanceof ObjectNode) {
final ObjectNode alter = (ObjectNode) node;
alter.remove("name");
}
return JsonValue.json(JsonValue.object(JsonValue.field(JSON_OBJ_TITLE, resourceId), JsonValue.field(JSON_OBJ_LOGICAL, logical), JsonValue.field(JSON_OBJ_CONFIG, schema)));
} catch (JsonMappingException e) {
if (debug.errorEnabled()) {
debug.error("ConditionTypesResource :: JSONIFY - Error applying " + "jsonification to the Condition class representation.", e);
}
return null;
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project camel by apache.
the class MultiSelectPicklistDeserializer method deserialize.
@Override
public Object deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
// validate enum class
if (enumClass == null) {
throw new JsonMappingException(jp, "Unable to parse unknown pick-list type");
}
final String listValue = jp.getText();
try {
// parse the string of the form value1;value2;...
final String[] value = listValue.split(";");
final int length = value.length;
final Object resultArray = Array.newInstance(enumClass, length);
for (int i = 0; i < length; i++) {
// use factory method to create object
Array.set(resultArray, i, factoryMethod.invoke(null, value[i].trim()));
}
return resultArray;
} catch (Exception e) {
throw new JsonParseException(jp, "Exception reading multi-select pick list value", jp.getCurrentLocation());
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project JMRI by JMRI.
the class PanelServlet method getJsonPanel.
@Override
protected String getJsonPanel(String name) {
log.debug("Getting {} for {}", getPanelType(), name);
try {
PanelEditor editor = (PanelEditor) getEditor(name);
ObjectNode root = this.mapper.createObjectNode();
ObjectNode panel = root.putObject("panel");
JFrame frame = editor.getTargetFrame();
panel.put("name", name);
panel.put("height", frame.getContentPane().getHeight());
panel.put("width", frame.getContentPane().getWidth());
panel.put("panelheight", frame.getContentPane().getHeight());
panel.put("panelwidth", frame.getContentPane().getWidth());
panel.put("showtooltips", editor.showTooltip());
panel.put("controlling", editor.allControlling());
if (editor.getBackgroundColor() != null) {
ObjectNode color = panel.putObject("backgroundColor");
color.put("red", editor.getBackgroundColor().getRed());
color.put("green", editor.getBackgroundColor().getGreen());
color.put("blue", editor.getBackgroundColor().getBlue());
}
// include contents
log.debug("N elements: {}", editor.getContents().size());
for (Positionable sub : editor.getContents()) {
try {
// TODO: get all panel contents as JSON
// I tried using JavaBean Introspection to simply build the contents using Jackson Databindings,
// but when a panel element has a reference to the panel or to itself as a property, this leads
// to infinite recursion
} catch (Exception ex) {
log.error("Error storing panel element: " + ex, ex);
}
}
return this.mapper.writeValueAsString(root);
} catch (NullPointerException ex) {
log.warn("Requested Panel [" + name + "] does not exist.");
return "ERROR Requested panel [" + name + "] does not exist.";
} catch (JsonGenerationException e) {
log.error("Error generating JSON", e);
return "ERROR " + e.getLocalizedMessage();
} catch (JsonMappingException e) {
log.error("Error mapping JSON", e);
return "ERROR " + e.getLocalizedMessage();
} catch (IOException e) {
log.error("IOException", e);
return "ERROR " + e.getLocalizedMessage();
}
}
Aggregations