Package org.jongo

Examples of org.jongo.Mapper


    @Test
    //https://github.com/bguerout/jongo/issues/226
    public void canSetAFieldToNullDuringAnUpdate() throws Exception {

        Mapper mapper = new JacksonMapper.Builder().addModifier(new MapperModifier() {
            public void modify(ObjectMapper mapper) {
                mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
            }
        }).build();
        Jongo jongo = new Jongo(getDatabase(), mapper);
        MongoCollection friends = jongo.getCollection("friends");
        Friend friend = new Friend("Peter", "31 rue des Lilas");
View Full Code Here


    @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);

        assertThat(friend.getName()).isEqualTo("Doe");
    }
View Full Code Here

    @Test
    public void canAddSerializer() throws Exception {

        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

    @Test
    public void canSetVisibilityChecker() throws Exception {

        PojoWithGetter robert = new PojoWithGetter("Robert", "Sax");

        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

    @Test
    public void canAddModule() throws Exception {

        ObjectId oid = new ObjectId("504482e5e4b0d1b2c47fff66");
        Friend friend = new Friend(oid, "Robert");
        Mapper mapper = new JacksonMapper.Builder()
                .registerModule(new Module() {
                    @Override
                    public String getModuleName() {
                        return "test-module";
                    }

                    @Override
                    public Version version() {
                        return new Version(2, 0, 0, "", "org.jongo", "testmodule");
                    }

                    @Override
                    public void setupModule(SetupContext setupContext) {
                        SimpleDeserializers deserializers = new SimpleDeserializers();
                        deserializers.addDeserializer(String.class, new DoeJsonDeserializer());
                        setupContext.addDeserializers(deserializers);
                    }
                })
                .build();

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

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

        QueryFactory factory = new QueryFactory() {
            public Query createQuery(String query, Object... parameters) {
                return null;
            }
        };
        Mapper mapper = new JacksonMapper.Builder()
                .withObjectIdUpdater(objectIdUpdater)
                .withQueryFactory(factory)
                .build();

        assertThat(mapper.getObjectIdUpdater()).isEqualTo(objectIdUpdater);
        assertThat(mapper.getQueryFactory()).isEqualTo(factory);
    }
View Full Code Here

            return collection.getName();
        }

        @Override
        public MongoCollection get() {
            final Mapper mapper = getMapper();

            MongoCollection mongoCollection = new MongoCollection(
                    collection.get().getDBCollection(),
                    new Mapper() {
                        @Override
                        public Marshaller getMarshaller() {
                            return mapper.getMarshaller();
                        }

                        @Override
                        public Unmarshaller getUnmarshaller() {
                            return mapper.getUnmarshaller();
                        }

                        @Override
                        public ObjectIdUpdater getObjectIdUpdater() {
                            return new ObjectIdUpdater() {
                                @Override
                                public boolean mustGenerateObjectId(Object pojo) {
                                    return mapper.getObjectIdUpdater().mustGenerateObjectId(pojo);
                                }

                                @Override
                                public Object getId(Object pojo) {
                                    return mapper.getObjectIdUpdater().getId(pojo);
                                }

                                @Override
                                public void setObjectId(Object target, ObjectId id) {
                                    mapper.getObjectIdUpdater().setObjectId(target,
                                            new ObjectId(iteratingSequence.next().or(id.toString())));
                                }
                            };
                        }

                        @Override
                        public QueryFactory getQueryFactory() {
                            return mapper.getQueryFactory();
                        }
                    });
            return mongoCollection;
        }
View Full Code Here

                new SingleNameFactoryMachine<>(0, new StdMachineEngine<ComponentCustomizerEngine>(
                        Name.of(ComponentCustomizerEngine.class, "JongoCollectionSequenceSupplier"),
                        BoundlessComponentBox.FACTORY) {
                    @Override
                    protected ComponentCustomizerEngine doNewComponent(SatisfiedBOM satisfiedBOM) {
                        final Mapper mapper = satisfiedBOM.getOne(mapperQuery).get().getComponent();
                        final ObjectIdUpdater objectIdUpdater = mapper.getObjectIdUpdater();
                        return new SingleComponentClassCustomizerEngine<JongoCollection>(0, JongoCollection.class) {
                            @Override
                            public NamedComponent<JongoCollection> customize(NamedComponent<JongoCollection> namedComponent) {
                                final JongoCollection collection = namedComponent.getComponent();
                                return new NamedComponent<>(namedComponent.getName(),
View Full Code Here

            MongoCollection mongoCollection = collection.get();
            if (tape != null) {
                tape.recordCollection(mongoCollection);
                mongoCollection = new MongoCollection(
                        mongoCollection.getDBCollection(),
                        new Mapper() {
                            @Override
                            public Marshaller getMarshaller() {
                                return mapper.getMarshaller();
                            }
View Full Code Here

TOP

Related Classes of org.jongo.Mapper

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.