Search in sources :

Example 1 with UnrecognizedPropertyException

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);
}
Also used : JSONAuditLogMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONAuditLogMarshaller) OutputStream(java.io.OutputStream) FileWriter(java.io.FileWriter) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) AnnotationIntrospector(org.codehaus.jackson.map.AnnotationIntrospector) UnrecognizedPropertyException(org.codehaus.jackson.map.exc.UnrecognizedPropertyException) AuditLog(com.emc.storageos.db.client.model.AuditLog) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) BufferedWriter(java.io.BufferedWriter) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 2 with UnrecognizedPropertyException

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);
}
Also used : Stat(com.emc.storageos.db.client.model.Stat) OutputStream(java.io.OutputStream) FileWriter(java.io.FileWriter) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) AnnotationIntrospector(org.codehaus.jackson.map.AnnotationIntrospector) UnrecognizedPropertyException(org.codehaus.jackson.map.exc.UnrecognizedPropertyException) JSONStatMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONStatMarshaller) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 3 with UnrecognizedPropertyException

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()));
    }
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) Command(org.activityinfo.legacy.shared.command.Command) UnrecognizedPropertyException(org.codehaus.jackson.map.exc.UnrecognizedPropertyException) JsonNode(org.codehaus.jackson.JsonNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) UnrecognizedPropertyException(org.codehaus.jackson.map.exc.UnrecognizedPropertyException) IOException(java.io.IOException) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException)

Example 4 with UnrecognizedPropertyException

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);
}
Also used : JSONEventMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller) OutputStream(java.io.OutputStream) FileWriter(java.io.FileWriter) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) AnnotationIntrospector(org.codehaus.jackson.map.AnnotationIntrospector) UnrecognizedPropertyException(org.codehaus.jackson.map.exc.UnrecognizedPropertyException) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) BufferedWriter(java.io.BufferedWriter) Event(com.emc.storageos.db.client.model.Event) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 UnrecognizedPropertyException (org.codehaus.jackson.map.exc.UnrecognizedPropertyException)4 File (java.io.File)3 FileWriter (java.io.FileWriter)3 OutputStream (java.io.OutputStream)3 AnnotationIntrospector (org.codehaus.jackson.map.AnnotationIntrospector)3 JaxbAnnotationIntrospector (org.codehaus.jackson.xc.JaxbAnnotationIntrospector)3 Test (org.junit.Test)3 BufferedWriter (java.io.BufferedWriter)2 OutputStreamWriter (java.io.OutputStreamWriter)2 JSONAuditLogMarshaller (com.emc.storageos.api.service.impl.resource.utils.JSONAuditLogMarshaller)1 JSONEventMarshaller (com.emc.storageos.api.service.impl.resource.utils.JSONEventMarshaller)1 JSONStatMarshaller (com.emc.storageos.api.service.impl.resource.utils.JSONStatMarshaller)1 AuditLog (com.emc.storageos.db.client.model.AuditLog)1 Event (com.emc.storageos.db.client.model.Event)1 Stat (com.emc.storageos.db.client.model.Stat)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Command (org.activityinfo.legacy.shared.command.Command)1 JsonNode (org.codehaus.jackson.JsonNode)1