سؤال

I'm trying to run an "hello world" with Jongo

I added the jar manually (not with Maven)

This is the code I ran:

public  class Friend {  
    @Id 
    private String myId;
}

public static void main(String[] args) {
MongoClient mongoClient = new MongoClient( "mydb.mongohq.com", 10014 );
        DB db = mongoClient.getDB( "db-name" );
        Jongo jongo = new Jongo(db);
        MongoCollection friends = jongo.getCollection("collection");
        Friend joe = new Friend();
        friends.save(joe);
}

And I'm getting this mistake:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
    at java.lang.System.arraycopy(Native Method)
    at org.bson.io.PoolOutputBuffer.write(PoolOutputBuffer.java:74)
    at org.bson.LazyBSONObject.pipe(LazyBSONObject.java:451)
    at org.jongo.bson.BsonDBEncoder.writeObject(BsonDBEncoder.java:39)
    at com.mongodb.OutMessage.putObject(OutMessage.java:289)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:239)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:204)
    at com.mongodb.DBCollection.insert(DBCollection.java:148)
    at com.mongodb.DBCollection.insert(DBCollection.java:91)
    at com.mongodb.DBCollection.save(DBCollection.java:810)
    at org.jongo.Insert.save(Insert.java:55)
    at org.jongo.MongoCollection.save(MongoCollection.java:128)
هل كانت مفيدة؟

المحلول

Assuming that you have added the jar dependencies — Jackson 2.1, Bson4Jackson 2.1 and Mongo Java Driver 2.9+ — it seems to me that your Friend class de not have a private constructor. The mapping section of the documentation explain this in details.

نصائح أخرى

My mistake was using Jackson 2.2.1 and not 2.1, after changing it to 2.1 it is working great.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top