[JAVA-2972] serialization by field Convention Created: 11/Sep/18  Updated: 08/Jan/19  Resolved: 08/Jan/19

Status: Closed
Project: Java Driver
Component/s: POJO
Affects Version/s: 3.8.1
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Vitali Pankraz Assignee: Ross Lawley
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

JDK 8, Windows 10


Issue Links:
Duplicate
duplicates JAVA-3097 Create Convention that customises whi... Backlog

 Description   

When serializing a POJO the properties are identified by** getter methods, *setter methods and* fields. (see http://mongodb.github.io/mongo-java-driver/3.6/bson/pojos/)

If the POJO impl. contains non standard getter e.g.

 
public class SomeClass {
 
private String someField1;
 
private String someField2;
 
 
 
public String getSomeField1(){
 
  return someField1;
 
}
 
 
 
public String getSomeField2(){
 
  return someField2;
 
}
 
 
 
public Integer getCalculation(){
  // return some calculated value
 
}
 
}

a property "calculation" with some value will be serialized which is not intendet. Sure, you can use some @BsonIgnore annotation to avoid that but you have to check the serialization bahaviour every time the POJO is extended by some get*() method. 

Another issue is when integrating a given POJO with large amount of such non-standard get*() methods.

It would be a great benefit to register some Convention which says: "serialize only the fields and ignore getter methods".

 



 Comments   
Comment by Ross Lawley [ 08/Jan/19 ]

Please watch JAVA-3097 for updates on this feature.

Comment by Ross Lawley [ 08/Jan/19 ]

vitali,

Thanks for the ticket, a similar request came out of another ticket and resulted in JAVA-3097. I think if the driver provides a flexible convention that allows explicit definitions of what should be included then it will achieve your goals as well.

Ross

Generated at Thu Feb 08 08:58:29 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.