Search in sources :

Example 1 with StdDeserializer

use of com.fasterxml.jackson.databind.deser.std.StdDeserializer in project pentaho-metaverse by pentaho.

the class KettleObjectMapperTest method testReadValue.

@Test
public void testReadValue() throws Exception {
    StdDeserializer deserializer = new TransMetaJsonDeserializer(TransMeta.class, null);
    deserializers.add(deserializer);
    mapper = new KettleObjectMapper(null, deserializers);
    assertNotNull(mapper);
    mapper.readValue(TRANS_JSON, TransMeta.class);
}
Also used : StdDeserializer(com.fasterxml.jackson.databind.deser.std.StdDeserializer) Test(org.junit.Test)

Example 2 with StdDeserializer

use of com.fasterxml.jackson.databind.deser.std.StdDeserializer in project bson4jackson by michel-kraemer.

the class BsonParserTest method parseObjectId.

/**
 * Check if org.bson.types.ObjectId can be serialized and deserialized as
 * a byte array. See issue #38
 * @throws Exception if something goes wrong
 */
@Test
public void parseObjectId() throws Exception {
    class ObjectIdDeserializer extends StdDeserializer<org.bson.types.ObjectId> {

        private static final long serialVersionUID = 6934309887169924897L;

        protected ObjectIdDeserializer() {
            super(org.bson.types.ObjectId.class);
        }

        @Override
        public org.bson.types.ObjectId deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonGenerationException {
            return new org.bson.types.ObjectId(jp.getBinaryValue());
        }
    }
    org.bson.types.ObjectId oid = new org.bson.types.ObjectId();
    BSONObject o = new BasicBSONObject();
    o.put("oid", oid.toByteArray());
    SimpleModule mod = new SimpleModule();
    mod.addDeserializer(org.bson.types.ObjectId.class, new ObjectIdDeserializer());
    ObjectIdClass res = parseBsonObject(o, ObjectIdClass.class, mod);
    assertEquals(oid, res.oid);
}
Also used : StdDeserializer(com.fasterxml.jackson.databind.deser.std.StdDeserializer) ObjectId(de.undercouch.bson4jackson.types.ObjectId) BasicBSONObject(org.bson.BasicBSONObject) BSONObject(org.bson.BSONObject) BasicBSONObject(org.bson.BasicBSONObject) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.junit.Test)

Aggregations

StdDeserializer (com.fasterxml.jackson.databind.deser.std.StdDeserializer)2 Test (org.junit.Test)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 ObjectId (de.undercouch.bson4jackson.types.ObjectId)1 BSONObject (org.bson.BSONObject)1 BasicBSONObject (org.bson.BasicBSONObject)1