Package org.jongo.bson

Examples of org.jongo.bson.BsonDocument


    }

    @Test
    public void canMarshall() {

        BsonDocument doc = engine.marshall(new Fox("fantastic", "roux"));

        DBObject dbo = doc.toDBObject();
        assertThat(dbo.get("_class")).isEqualTo("org.jongo.model.Fox");
        assertThat(dbo.get("name")).isEqualTo("fantastic");
        assertThat(dbo.get("color")).isEqualTo("roux");
    }
View Full Code Here


    }

    @Test
    public void canUnmarshallBson() throws IOException {

        BsonDocument document = bsonify("{'address': '22 rue des murlins'}");

        Friend friend = engine.unmarshall(document, Friend.class);

        assertThat(friend.getAddress()).isEqualTo("22 rue des murlins");
    }
View Full Code Here

public class JacksonMapperTest {

    @Test
    public void canAddDeserializer() throws Exception {

        BsonDocument document = Bson.createDocument(new BasicDBObject("name", "robert"));
        Mapper mapper = new JacksonMapper.Builder()
                .addDeserializer(String.class, new DoeJsonDeserializer())
                .build();

        Friend friend = mapper.getUnmarshaller().unmarshall(document, Friend.class);
View Full Code Here

        Friend robert = new Friend("Robert");
        Mapper mapper = new JacksonMapper.Builder()
                .addSerializer(String.class, new DoeJsonSerializer())
                .build();

        BsonDocument document = mapper.getMarshaller().marshall(robert);

        assertThat(document.toString()).contains("{ \"name\" : \"Doe\"}");
    }
View Full Code Here

        Mapper mapper = new JacksonMapper.Builder()
                .setVisibilityChecker(new VisibilityChecker.Std(JsonAutoDetect.Visibility.PUBLIC_ONLY).withFieldVisibility(JsonAutoDetect.Visibility.NONE))
                .build();

        BsonDocument document = mapper.getMarshaller().marshall(robert);

        assertThat(document.toString()).isEqualTo("{ \"firstName\" : \"Robert\"}");
    }
View Full Code Here

                        setupContext.addDeserializers(deserializers);
                    }
                })
                .build();

        BsonDocument document = mapper.getMarshaller().marshall(friend);

        assertThat(document.toString()).contains("\"_id\" : { \"$oid\" : \"504482e5e4b0d1b2c47fff66\"}");
    }
View Full Code Here

        JacksonEngine custom = createProcessorWithView(Views.Public.class);
        Fox vixen = new Fox("fantastic", "roux");
        vixen.setGender("female");

        BsonDocument doc = custom.marshall(vixen);

        DBObject result = doc.toDBObject();
        assertThat(result.get("gender")).isNull();
        assertThat(result.get("_class")).isEqualTo("org.jongo.model.Fox");
        assertThat(result.get("name")).isEqualTo("fantastic");
        assertThat(result.get("color")).isEqualTo("roux");
    }
View Full Code Here

        JacksonEngine custom = createProcessorWithView(Views.Private.class);
        Fox vixen = new Fox("fantastic", "roux");
        vixen.setGender("female");

        BsonDocument doc = custom.marshall(vixen);

        DBObject result = doc.toDBObject();
        assertThat(result.get("_class")).isEqualTo("org.jongo.model.Fox");
        assertThat(result.get("name")).isEqualTo("fantastic");
        assertThat(result.get("color")).isEqualTo("roux");
        assertThat(result.get("gender")).isEqualTo("female");
    }
View Full Code Here

    }

    @Test
    public void respectsJsonPublicViewOnUnmarshall() throws Exception {

        BsonDocument doc = bsonify("{'_class':'org.jongo.model.Fox','name':'fantastic','color':'roux','gender':'female'}");
        JacksonEngine custom = createProcessorWithView(Views.Public.class);

        Fox fox = custom.unmarshall(doc, Fox.class);

        assertThat(fox.getGender()).isNull();
View Full Code Here

    }

    @Test
    public void respectsJsonPrivateViewOnUnmarshall() throws Exception {

        BsonDocument doc = bsonify("{'_class':'org.jongo.model.Fox','name':'fantastic','color':'roux','gender':'female'}");
        JacksonEngine custom = createProcessorWithView(Views.Private.class);

        Fox fox = custom.unmarshall(doc, Fox.class);

        assertThat(fox.getGender()).isEqualTo("female");
View Full Code Here

TOP

Related Classes of org.jongo.bson.BsonDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.