You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I use the JacksonMapper from the KMongoConfiguration I get an valid JSON in with "contains" contains only the URIs from the containing entries.
But when I try to Insert it into the MongoDB I get this Exception:
Caused by: java.lang.IllegalStateException: XXX has to be class org.bson.types.ObjectId
at org.litote.kmongo.jackson.KMongoBsonFactory$KMongoBsonGenerator.writeObjectId(KMongoBsonFactory.kt:49)
at com.fasterxml.jackson.databind.ser.impl.WritableObjectId.writeAsField(WritableObjectId.java:67)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase._serializeWithObjectId(BeanSerializerBase.java:627)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:148)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
If I change the Object to this I get the exception also...
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator::class , property= "_id")
class Entry(uri: String) {
@BsonId
val _id: Id<Entry> = StringId(uri)
@JsonIdentityReference(alwaysAsId = true)
var contains : MutableSet<Entry> = Collections.synchronizedSet(HashSet())
As far as I can see the StringID Object are changed to a String inside Jackson
public void writeAsField(JsonGenerator gen, SerializerProvider provider,
ObjectIdWriter w) throws IOException
{
idWritten = true;
// 03-Aug-2013, tatu: Prefer Native Object Ids if available
if (gen.canWriteObjectId()) {
// Need to assume String(ified) ids, for now... could add 'long' variant?
gen.writeObjectId(String.valueOf(id));
return;
}
SerializableString name = w.propertyName;
if (name != null) {
gen.writeFieldName(name);
w.serializer.serialize(id, gen, provider);
}
}
The text was updated successfully, but these errors were encountered:
Well... KMongo did not support to generate id as String with @JsonIdentityInfo. This is fixed in snapshot.
Here is a way to generate an Id with the fix:
Hi I have an Object like this:
When I use the JacksonMapper from the KMongoConfiguration I get an valid JSON in with "contains" contains only the URIs from the containing entries.
But when I try to Insert it into the MongoDB I get this Exception:
If I change the Object to this I get the exception also...
As far as I can see the StringID Object are changed to a String inside Jackson
The text was updated successfully, but these errors were encountered: