0

I have a java class as follows

@Data
@Document(collection="sample_collection")
public class sampleClass {
  private Instant createTime;
  private Object payLoad;
  // some more fields
}

The payload object can be null or object of different classes, and can contain a field of type byteBuffer.

Now, while trying to save this to Mongo as a document, I get no issues, but which retrieving the document, I get the instantiationException( whenever the payload object is populated and has the byteBuffer field )

Below are the exception details:

org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate java.nio.HeapByteBuffer using constructor NO_CONSTRUCTOR with arguments 
at org.springframework.data.convert.ReflectionEntityInstantiator.createInstance
at org.springframework.data.convert.ClassGeneratingEntityInstantiator.createInstance
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read

I'm unable to find a way to define a constructor for the HeapByteBuffer field. Any leads would be appreciated.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348

1 Answers1

0

From my point of view you should use more concrete class as field in your entity OR you can try to use Converters as workaround of this issue: Setup custom converters in Spring Data Mongo

Nikita
  • 94
  • 1
  • 3