[JAVA-1820] Unable to Map JSON to POJO Created: 19/May/15  Updated: 11/Sep/19  Resolved: 20/May/15

Status: Closed
Project: Java Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Minor - P4
Reporter: murali Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 14.04



 Description   

Unable to Map JSON to POJO.

I have inserted JSON from R tool.
I am able to read and map the JSON to Java POJO using MongoTemplate API(Spring) in my windows environment.
But If I try to Map JSON to Java POJO using MongoTemplate API(Spring)
in Ubuntu environment,It is failing and throwing exception.

Please find the attached error log and bson dump .



 Comments   
Comment by Ross Lawley [ 20/May/15 ]

As you can read and Map to a POJO when you manually insert the data, you have confirmed this isn't a Java driver issue. For that reason I'm closing this ticket as "Works as Designed".

Rather it seems that this is an integration issue with the tooling you are using for whatever reason. There is little information to go on to help identify the cause and as mentioned previously this isn't the best place to get support.

Please could you post your question to mongodb-user mailinglist or stackoverflow and link it to this ticket so I can follow it. The reasons being are you will reach a boarder audience there, some of whom may have had similar issues in the past.

It might prove helpful in your post to include what the JSON looks like and the POJO object as well. Also, provide version information, what version of Spring, Java Driver, MongoDB etc.

Comment by murali [ 20/May/15 ]

The data set in both environments(ubuntu and Windows) is same.
Steps to reproduce :
1) Create JSON from R tool/Script and save in Mongo db.
2) Fetch the JSON from java rest API (Mapping to POJO and return the POJO to client)
Note:If I copy the same JSON (which was created by R tool ) from Mongo terminal(Ubuntu) and if I re-insert using Mongo commands(like db.insert),
I am able to read and Map to POJO.

Comment by Ross Lawley [ 19/May/15 ]

Hi murali.lancer,

It seems strange that it works on Windows but not on Ubuntu, is the dataset the same? I'd see anything attached to the ticket - can you provide a reproduction case? Also, does querying the data from the mongo shell work as expected?

Just to let you know for future reference, the JAVA Jira project is really for Java driver bugs or feature requests. The best place for questions regarding MongoDB usage or the Java driver specifics is the mongodb-user mailinglist or stackoverflow as you will reach a boarder audience there and who may have had similar issues in the past.

Ross

Comment by murali [ 19/May/15 ]

Java.lang.IllegalArgumentException: BasicBSONList can only work with numeric keys, not: []
at org.bson.types.BasicBSONList._getInt(BasicBSONList.java:161)
at org.bson.types.BasicBSONList._getInt(BasicBSONList.java:152)
at org.bson.types.BasicBSONList.put(BasicBSONList.java:66)
at org.bson.BasicBSONCallback.objectStart(BasicBSONCallback.java:69)
at com.mongodb.DefaultDBCallback.objectStart(DefaultDBCallback.java:64)
at org.bson.BasicBSONCallback.objectStart(BasicBSONCallback.java:63)
at org.bson.BasicBSONDecoder.decodeElement(BasicBSONDecoder.java:205)
at org.bson.BasicBSONDecoder.decodeElement(BasicBSONDecoder.java:196)
at org.bson.BasicBSONDecoder._decode(BasicBSONDecoder.java:79)
at org.bson.BasicBSONDecoder.decode(BasicBSONDecoder.java:57)
at com.mongodb.DefaultDBDecoder.decode(DefaultDBDecoder.java:61)
at com.mongodb.Response.<init>(Response.java:83)
at com.mongodb.DBPort.go(DBPort.java:142)
at com.mongodb.DBPort.call(DBPort.java:92)
at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:244)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:216)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:288)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:273)
at com.mongodb.DBCollection.findOne(DBCollection.java:728)
at com.mongodb.DBCollection.findOne(DBCollection.java:670)
at org.springframework.data.mongodb.core.MongoTemplate$FindOneCallback.doInCollection(MongoTemplate.java:2069)
at org.springframework.data.mongodb.core.MongoTemplate$FindOneCallback.doInCollection(MongoTemplate.java:2053)
at org.springframework.data.mongodb.core.MongoTemplate.executeFindOneInternal(MongoTemplate.java:1828)
at org.springframework.data.mongodb.core.MongoTemplate.doFindOne(MongoTemplate.java:1645)
at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:560)
at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:555)

Comment by murali [ 19/May/15 ]

Please help me

Generated at Thu Feb 08 08:55:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.