Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serialize/map NULL values from db to fields #3

Closed
Pokerkoffer opened this issue Jan 7, 2017 · 3 comments
Closed

serialize/map NULL values from db to fields #3

Pokerkoffer opened this issue Jan 7, 2017 · 3 comments

Comments

@Pokerkoffer
Copy link

Pokerkoffer commented Jan 7, 2017

Hi there,

JSON in MongoDB 3.x:

{
    "_id" : "somehex",
    "name" : "a Name",
   "someobject": null
}

Class to map to:

@Entity
public class MyClass {
    @Id
    @JsonProperty
    private String id;

    @NotEmpty
    @JsonProperty
    private String name;

    @JsonProperty
    private SomeObject someobject;
}

My code, that retrieves the values from mongodb:

        FindIterable<MyClass> myClasses = myClassCollection.find(query.toBson(true));
        return myClasses.into(new ArrayList<MyClass>());

When i try to map this back to a class it gives me an error:

readStartDocument can only be called when CurrentBSONType is DOCUMENT, not when CurrentBSONType is NULL.

Stacktrace:

ERROR [2017-01-07 15:03:58,066] com.washingtonpost.dropwizard.exceptions.mappers.RuntimeExceptionMapper: readStartDocument can only be called when CurrentBSONType is DOCUMENT, not when CurrentBSONType is NULL.
! org.bson.BsonInvalidOperationException: readStartDocument can only be called when CurrentBSONType is DOCUMENT, not when CurrentBSONType is NULL.
! at org.bson.AbstractBsonReader.verifyBSONType(AbstractBsonReader.java:692)
! at org.bson.AbstractBsonReader.checkPreconditions(AbstractBsonReader.java:724)
! at org.bson.AbstractBsonReader.readStartDocument(AbstractBsonReader.java:452)
! at eu.dozd.mongo.EntityCodec.decode(EntityCodec.java:63)
! at eu.dozd.mongo.EntityCodec.decode(EntityCodec.java:69)
! at com.mongodb.operation.CommandResultArrayCodec.decode(CommandResultArrayCodec.java:52)
! at com.mongodb.operation.CommandResultDocumentCodec.readValue(CommandResultDocumentCodec.java:53)
! at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:84)
! at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:41)
! at org.bson.codecs.configuration.LazyCodec.decode(LazyCodec.java:47)
! at org.bson.codecs.BsonDocumentCodec.readValue(BsonDocumentCodec.java:101)
! at com.mongodb.operation.CommandResultDocumentCodec.readValue(CommandResultDocumentCodec.java:56)
! at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:84)
! at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:41)
! at com.mongodb.connection.ReplyMessage.<init>(ReplyMessage.java:57)
! at com.mongodb.connection.CommandProtocol.getResponseDocument(CommandProtocol.java:139)
! at com.mongodb.connection.CommandProtocol.execute(CommandProtocol.java:118)
! at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:168)
! at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:289)
! at com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:176)
! at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:216)
! at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:207)
! at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:113)
! at com.mongodb.operation.FindOperation$1.call(FindOperation.java:516)
! at com.mongodb.operation.FindOperation$1.call(FindOperation.java:510)
! at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:431)
! at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:404)
! at com.mongodb.operation.FindOperation.execute(FindOperation.java:510)
! at com.mongodb.operation.FindOperation.execute(FindOperation.java:81)
! at com.mongodb.Mongo.execute(Mongo.java:836)
! at com.mongodb.Mongo$2.execute(Mongo.java:823)
! at com.mongodb.OperationIterable.iterator(OperationIterable.java:47)
! at com.mongodb.OperationIterable.forEach(OperationIterable.java:70)
! at com.mongodb.OperationIterable.into(OperationIterable.java:82)
! at com.mongodb.FindIterableImpl.into(FindIterableImpl.java:171)
.
.
.

How can i fix this? Is this an error when mapping back to POJOs?

Thanks!

@dozd
Copy link
Owner

dozd commented Jan 7, 2017

I'll have a look at it.

@dozd dozd closed this as completed in 572e74a Jan 7, 2017
@dozd
Copy link
Owner

dozd commented Jan 7, 2017

Will be released shortly as 1.0.7.

@Pokerkoffer
Copy link
Author

Awesome, Thank you very much!

dozd added a commit that referenced this issue Jan 31, 2017
Signed-off-by: Zdenek Dolezal <zdenek.dolezal@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants