Comments (2)
I guess that this isn't possible to fix, this happens due to type loss, so the parser needs to do heuristics to figure out if it is a map or a array.
The problem happens when you try to use 0
on a map, because it matches the heuristics, it thinks it is a numerically indexed array... causing issues.
from jackson-dataformat-hocon.
It looks like @jclawson is inactive, so I guess this bug won't ever be fixed.
In the meantime, I made a custom deserializer with a hacky fix for this issue.
class FixedMapDeserializer : JsonDeserializer<Map<*, *>>() {
override fun deserialize(p0: JsonParser, p1: DeserializationContext): Map<*, *> {
val any = p0.readValueAsTree<TreeNode>()
if (any.isArray) {
val values = mutableMapOf<Any?, Any?>()
repeat(any.size()) {
values[it] = any.get(it)
}
return values
} else {
val values = mutableMapOf<Any?, Any?>()
any.fieldNames().forEach {
values[it] = any.get(it)
}
return values
}
}
}
Then, on your HOCON Mapper
val module = SimpleModule()
module.setDeserializerModifier(object: BeanDeserializerModifier() {
override fun modifyMapDeserializer(config: DeserializationConfig, type: MapType, beanDesc: BeanDescription, deserializer: JsonDeserializer<*>): JsonDeserializer<*> {
return FixedMapDeserializer()
}
})
mapper.registerModule(module)
The deserializer is a very simple & quick fix: If the JSON input is a array but Jackson expects a class, it converts the JSON to a Map (first array entry = 0 to mapValue
on the map), if else, it just parses as a map.
I didn't test it on every possible combination, but on my quick tests: It works pretty well!
from jackson-dataformat-hocon.
Related Issues (8)
- Pom changes as part of PR10
- README.md has wrong coordinates
- cannot include yaml file
- Why is release 1.1.1 not in the central maven repository?
- Implement HoconTreeTraversingParser#getTokenLocation using ConfigOrigin HOT 7
- Convert dash case to camel case HOT 3
- Transforming from HOCON to JSON before deserialization
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-dataformat-hocon.