Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2695

Add support for Map<String, Object> in PojoCodec

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.7.0
    • Affects Version/s: 3.5.0
    • Component/s: POJO
    • None

      Hi guys,

      Our model consist of pojo classes containing Map<String,Object> properties field.
      I try to user PojoCodec to save them in Mongo, however:

      1. In PojoCodecImpl, method addToCache determines the codec using type parameters: "getCodecFromTypeData(typeData.getTypeParameters().get(1)));" and saving the pojo results in "CodecConfigurationException: Can't find a codec for class java.lang.Object".

      2. I tried converting the Map<String,Object> field to org.bson.Document field before saving the Pojo in Mongo. However, when PojoBuilderHeper.getTypeData() method is called with org.bson.Document parameter, it checks that it is a Map, but there are no type parameters - and it throws an Exception (TypeData:114: typeParameters.size() != 2).

      If I forget about Pojo and save new Document(map) or Document.parse(jsonStringRepresentationOfMap) - java mongo driver can recognize the types correctly (dates, numbers, etc.) and save them in database. But if this map is a field in a Pojo - I cannot save it.

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            aneta stępień aneta stępień
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: