[JAVA-3416] Add Query Deserialization Validation for unrecognized fields Created: 29/Aug/19  Updated: 30/Mar/22

Status: Backlog
Project: Java Driver
Component/s: Codecs
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Evan Nixon Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
is related to JAVA-2218 Handle mismatches between document fi... Closed

 Description   

When the Mongo Java Driver deserializes BSON objects to POJOs it ignores fields that it does not recognize.

We are interested in a new feature that would enable throwing exceptions when unknown fields are found while deserializing using the PojoCodec. There is behavior analogous to this in the .NET driver.

It seems like there were a couple options discussed in the original POJO codec project when considering what to do when we find fields in documents that are not found in the Java POJO objects. Taken from that ticket, those were:

  1. (currently implemented) skipping that document field
  2. Throwing an exception
  3. Dumping extra fields to an optional BsonDocument on the object to hold the extra fields

Would you all consider an implementation that would (optionally) take approach (2) or (3)? We would be interested in submitting a PR if you agree that the functionality would be useful and worth adding.



 Comments   
Comment by Doug Tarr [ 04/Feb/20 ]

One use case is misspellings in queries:

This query is correct and would execute a wildcard match in mongot

$searchBeta: { term: { path: "name", query: "java*", wildcard: true } }

This query has a misspelling "wildcad" but since the "wildcard" parameter is optional, we would just execute a non-wildcard query (which would likely return empty results)

$searchBeta: { term: { path: "name", query: "java*", wildcad: true } }

We would like this second query to be able to throw an exception.

Comment by Jeffrey Yemin [ 04/Feb/20 ]

doug.tarr can you describe the usability problem in more detail? We want to understand what sort of pain this is causing.

Comment by Esha Bhargava [ 04/Feb/20 ]

jeff.yemin See Doug's ask above.

Comment by Doug Tarr [ 04/Feb/20 ]

Hi esha.bhargava - unfortunately we have not been able to prioritize this work, but it creates a usability problem for Search.

Wondering what the process would be to get this prioritized for the Java Drivers team? 

Comment by Evan Nixon [ 10/Sep/19 ]

Great - sounds good. We are aiming to do this this quarter - and would certainly appreciate talking through the design when this gets closer!

Comment by Esha Bhargava [ 10/Sep/19 ]

evan.nixon We'd love to see a PR for this. Let us know if you want to discuss the design.

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