Exemple #1
0
 private BsonDocument marshallDocument(Object pojo) {
   try {
     return marshaller.marshall(pojo);
   } catch (Exception e) {
     String message = String.format("Unable to save object %s due to a marshalling error", pojo);
     throw new IllegalArgumentException(message, e);
   }
 }
  private Object marshallDocument(Object parameter) {

    if (parameter instanceof Enum) {
      return marshallParameterAsPrimitive(parameter);
    } else {
      BsonDocument document = marshaller.marshall(parameter);

      if (hasBeenSerializedAsPrimitive(document)) {
        return marshallParameterAsPrimitive(parameter);
      } else {
        return document.toDBObject();
      }
    }
  }
 /**
  * The object may have been serialized to a primitive type with a custom serializer, so try again
  * after wrapping as an object property. We do this trick only as a falllback since it causes
  * Jackson to consider the parameter as "Object" and thus ignore any annotations that may exist on
  * its actual class.
  */
 private Object marshallParameterAsPrimitive(Object parameter) {
   Map<String, Object> primitiveWrapper = Collections.singletonMap("wrapped", parameter);
   BsonDocument document = marshaller.marshall(primitiveWrapper);
   return document.toDBObject().get("wrapped");
 }