use of org.codehaus.jackson.map.exc.UnrecognizedPropertyException in project coprhd-controller by CoprHD.
the class JSONAuditLogMarchallerTest method testJsonAuditLogMarshallingForNullLog.
@Test
public void testJsonAuditLogMarshallingForNullLog() throws URISyntaxException, IOException, MarshallingExcetion {
deleteIfExists(JsonTestOutputFile);
JSONAuditLogMarshaller jm = new JSONAuditLogMarshaller();
AuditLog log = null;
OutputStream output = new OutputStream() {
private StringBuilder string = new StringBuilder();
@Override
public void write(int b) throws IOException {
this.string.append((char) b);
}
public String toString() {
return this.string.toString();
}
};
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
jm.header(writer);
jm.marshal(log, writer);
jm.tailer(writer);
writer.close();
FileWriter fileWriter = new FileWriter(JsonTestOutputFile);
fileWriter.write(output.toString());
fileWriter.close();
ObjectMapper mapper = null;
mapper = new ObjectMapper();
AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
mapper.getDeserializationConfig().withAnnotationIntrospector(introspector);
try {
@SuppressWarnings("unused") AuditLog auditLog = mapper.readValue(new File(JsonTestOutputFile), AuditLog.class);
} catch (UnrecognizedPropertyException e) {
Assert.assertTrue(e.toString().contains("Unrecognized"));
}
deleteIfExists(JsonTestOutputFile);
}
use of org.codehaus.jackson.map.exc.UnrecognizedPropertyException in project coprhd-controller by CoprHD.
the class JSONStatMarshallerTest method testJsonStatMarshallingForNullEvent.
@Test
public void testJsonStatMarshallingForNullEvent() throws URISyntaxException, IOException, MarshallingExcetion {
deleteIfExists(JsonTestOutputFile);
JSONStatMarshaller jm = new JSONStatMarshaller();
Stat st = null;
OutputStream output = new OutputStream() {
private StringBuilder string = new StringBuilder();
@Override
public void write(int b) throws IOException {
this.string.append((char) b);
}
public String toString() {
return this.string.toString();
}
};
PrintWriter writer = new PrintWriter(output);
jm.header(writer);
jm.marshall(st, writer);
jm.tailer(writer);
writer.close();
FileWriter fileWriter = new FileWriter(JsonTestOutputFile);
fileWriter.write(output.toString());
fileWriter.close();
ObjectMapper mapper = null;
mapper = new ObjectMapper();
AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
mapper.getDeserializationConfig().withAnnotationIntrospector(introspector);
try {
@SuppressWarnings("unused") Stat stat = mapper.readValue(new File(JsonTestOutputFile), Stat.class);
} catch (UnrecognizedPropertyException e) {
Assert.assertTrue(e.toString().contains("Unrecognized"));
}
deleteIfExists(JsonTestOutputFile);
}
use of org.codehaus.jackson.map.exc.UnrecognizedPropertyException in project activityinfo by bedatadriven.
the class CommandDeserializer method deserialize.
@Override
public Command deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
ObjectNode root = (ObjectNode) mapper.readTree(jp);
String typeName = root.path("type").asText();
if (Strings.isNullOrEmpty(typeName)) {
throw new BadRpcRequest("Expected 'type' property on root object. You must specify a command type.");
}
Class commandClass;
try {
commandClass = lookupCommandClass(typeName);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to find command class for " + typeName, e);
throw new BadRpcRequest("Invalid command type '%s'", typeName);
}
JsonNode command = root.path("command");
if (!command.isObject()) {
throw new BadRpcRequest("Expected 'command' root object property.");
}
try {
return (Command) mapper.readValue(command, commandClass);
} catch (UnrecognizedPropertyException e) {
throw new BadRpcRequest("Unexpected property '%s'", formatPath(e.getPath()));
}
}
use of org.codehaus.jackson.map.exc.UnrecognizedPropertyException in project coprhd-controller by CoprHD.
the class JSONEventMarchallerTest method testJsonEventMarshallingForNullEvent.
@Test
public void testJsonEventMarshallingForNullEvent() throws URISyntaxException, IOException, MarshallingExcetion {
deleteIfExists(JsonTestOutputFile);
JSONEventMarshaller jm = new JSONEventMarshaller();
Event evt = null;
OutputStream output = new OutputStream() {
private StringBuilder string = new StringBuilder();
@Override
public void write(int b) throws IOException {
this.string.append((char) b);
}
public String toString() {
return this.string.toString();
}
};
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
jm.header(writer);
jm.marshal(evt, writer);
jm.tailer(writer);
writer.close();
FileWriter fileWriter = new FileWriter(JsonTestOutputFile);
fileWriter.write(output.toString());
fileWriter.close();
ObjectMapper mapper = null;
mapper = new ObjectMapper();
AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
mapper.getDeserializationConfig().withAnnotationIntrospector(introspector);
try {
@SuppressWarnings("unused") Event event = mapper.readValue(new File(JsonTestOutputFile), Event.class);
} catch (UnrecognizedPropertyException e) {
Assert.assertTrue(e.toString().contains("Unrecognized"));
}
deleteIfExists(JsonTestOutputFile);
}
Aggregations