Comments (9)
With json backend, you could enable JsonParser.Feature.STRICT_DUPLICATE_DETECTION
, but I am not sure it is supported by YAML module yet. Conversely, yaml module uses SnakeYaml
for decoding so it might already be checking for that.
Another relevant feature that is supported (since it's by jackson-databind
, not format modules) is DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY
, enabling of which would throw an exception if ObjectNode
(subtype of JsonNode
) had duplicate keys.
from jackson-dataformats-text.
FWIW Jackson 2.8.6 supports the JsonParser
flag. I just tested a YAML file with a duplicate key and got this exception:
Caused by: com.fasterxml.jackson.core.JsonParseException: Duplicate field 'Everything'
at [Source: java.io.BufferedInputStream@621319fd; line: 7, column: 11]
at com.fasterxml.jackson.core.json.JsonReadContext._checkDup(JsonReadContext.java:204)
at com.fasterxml.jackson.core.json.JsonReadContext.setCurrentName(JsonReadContext.java:198)
at com.fasterxml.jackson.dataformat.yaml.YAMLParser.nextToken(YAMLParser.java:367)
at com.fasterxml.jackson.core.JsonParser.nextFieldName(JsonParser.java:708)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBindStringKeyMap(MapDeserializer.java:505)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:362)
at com.fasterxml.jackson.module.scala.deser.UnsortedMapDeserializer.deserialize(UnsortedMapDeserializerModule.scala:76)
at com.fasterxml.jackson.module.scala.deser.UnsortedMapDeserializer.deserialize(UnsortedMapDeserializerModule.scala:39)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3798)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2915)
So I think this issue can be closed.
from jackson-dataformats-text.
@larsga Thank you for checking that -- I went ahead and added a unit test to confirm this, and guard against regression.
from jackson-dataformats-text.
it doesn't seem to work for me.
jackson-dataformat-yaml:2.9.2
jackson-databind:2.9.3
here is the code:
ObjectMapper objMapper = new ObjectMapper(new YAMLFactory()).enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION);
reader = objMapper.readerFor(ResponseParameterGroup[].class);
here is my YAML. The second 'response_parameters' seems to override the first one, while i expect an exception to occur:
- parameter_group_name: GROUP1 ## there are several groups showing just one for brevity
response_parameters:
- parameter_name: ObjectKey
output:
output_type: value
output_name: name
filters:
- filter_type: object_type_filter
filter_params:
object_type: shelf
- filter_type: data_filter
filter_params:
object_type: shelf
criteria_name: type
criteria_value: CPE1
response_parameters: ## this is the duplicate but i dont get any errors, this one seems to override the previous one
- parameter_name: ObjectKey
output:
output_type: value
output_name: name
filters:
- filter_type: object_type_filter
filter_params:
object_type: shelf
- filter_type: data_filter
filter_params:
object_type: shelf
criteria_name: type
criteria_value: CPE2
what am i doing wrong?
from jackson-dataformats-text.
I think I'd need to see definition of ResponseParameterGroup
, and call to read value(s) (you did include ObjectReader
but just need to see how it is called).
from jackson-dataformats-text.
hope this helps:
https://gist.github.com/nagarajasr/5c732575094601e678524d4a978cb865
DataPopulatorInputEntity is an empty marker interface.
and call to read values is along these lines:
public class DataPopulatorInputHelper<T extends DataPopulatorInputEntity> {
public T[] getInputRecords(Reader dpifr) throws DataPopulatorException {
T[] inputRecords = null;
try {
inputRecords = reader.readValue(dpifr);
} catch (....) {
// handle exceptions
}
}
}
thanks for your help!
from jackson-dataformats-text.
Ok. since it seems there is a remaining problem could you please file a new issue, for dup detection not working?
Ideally it'd be great to have simplified test case; I don't think complexity of model should matter here.
from jackson-dataformats-text.
Just in case someone reaches this page from google. Same case here, YAMLFactory -> ObjectMapper -> JsonNode, DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY works. It's reasonable to be controlled by a deserialization feature, as you do not "parse" json, but "deserialize" objects from YAML parser.
from jackson-dataformats-text.
@Hzj-jie ah! Thank you for pointing that out, that should be helpful.
from jackson-dataformats-text.
Related Issues (20)
- Parse YAML Keys with dots as dereferenced Map HOT 5
- Query on Jackson-dataformat-yaml usage HOT 2
- Missing Copyright information HOT 2
- Exception when attempting to use `ObjectMapper.readValues<T>(parser).readAll()` when parser is pointing to `START_ARRAY` HOT 5
- (yaml) Minor parsing validation miss: tagged as `int`, exception on underscore-only values
- `BigInteger` and `BigDecimal` are quoted if `CsvGenerator.Feature.ALWAYS_QUOTE_STRINGS` enabled
- Allow configuring Array value "wrappers" (like `[` and `]`) for `CsvSchema`
- `YAMLParser` throws unexpected `NullPointerException` in certain number parsing cases
- Yaml keys starting with number are being double quoted when mapper.writeValue() HOT 1
- Yaml Output differs from Json Output for Subtypes HOT 4
- INI Support HOT 4
- Unexpected `NumberFormatException` in `YAMLParser`
- Support max Read/Write nesting depth limits (`StreamReadConstraints`/`StreamWriteConstraints`) for YAML HOT 1
- Nesting objects within other objects (in YAML) HOT 1
- Weird issue with dates HOT 2
- Snakeyaml version used produces java.lang.NoSuchMethodError HOT 2
- Pkl support HOT 3
- TOML `TomlParserTest#float` fails on master (3.0) HOT 4
- Python Support HOT 2
- Allow CSV to differentiate between `null` and empty fields (foo,,bar vs. foo,"",bar) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jackson-dataformats-text.