jclawson / jackson-dataformat-hocon Goto Github PK
View Code? Open in Web Editor NEWJackson parser format for parsing HOCON
License: Apache License 2.0
Jackson parser format for parsing HOCON
License: Apache License 2.0
It was not my intent to include the pom change that changed the maven coordinates in PR10. You probably want to restore the following sections:
<groupId>com.jasonclawson</groupId>
<artifactId>jackson-dataformat-hocon</artifactId>
and
<url>https://github.com/jclawson/jackson-dataformat-hocon</url>
and
<scm>
<connection>scm:git:https://github.com/jclawson/jackson-dataformat-hocon.git</connection>
<developerConnection>scm:git:https://github.com/jclawson/jackson-dataformat-hocon.git</developerConnection>
<url>https://github.com/jclawson/jackson-dataformat-hocon/</url>
</scm>
and
<issueManagement>
<system>github</system>
<url>https://github.com/jclawson/jackson-dataformat-hocon/issues</url>
</issueManagement>
When parsing HOCON, the mapper does not recognize dash case (e.g. 'sample-key: "a"') to convert it to camel case ('sampleKey')
PS: Sorry for the previous title. My co-worker was messing with my computer.
If I have a .conf file:
{ a : { include required(classpath("myyaml")) } }
I will get a stack-trace with:
Caused by: java.io.IOException: resource not found on classpath: myyaml.conf
at com.typesafe.config.impl.Parseable$ParseableResources.rawParseValue(Parseable.java:735)
at com.typesafe.config.impl.Parseable$ParseableResources.rawParseValue(Parseable.java:710)
at com.typesafe.config.impl.Parseable.parseValue(Parseable.java:180)
... 47 more
and if I give a suffix:
{ a : { include required(classpath("myyaml.yaml")) } }
I will get:
Caused by: java.io.IOException: resource not found on classpath: myyaml.yaml.conf
at com.typesafe.config.impl.Parseable$ParseableResources.rawParseValue(Parseable.java:735)
at com.typesafe.config.impl.Parseable$ParseableResources.rawParseValue(Parseable.java:710)
at com.typesafe.config.impl.Parseable.parseValue(Parseable.java:180)
... 47 more
Seems this is not supported? But from the github readme I see:
In short, HOCON combines YAML, JSON, and Properties files into a single format. On most cases, YAML, JSON, and Properties formats are all valid HOCON--- and it can be mixed and matched at will. Check out the HOCON docs for more detail on the format.
Hello.
For deserialization, is there an advantage in using jackson-dataformat-hocon over transforming the HOCON configuration to JSON for Jackson's reading? Is jackson-dataformat-hocon more intended for serialization?
Sample code: String json = typesafeConfig.root().render(ConfigRenderOptions.concise());
Thanks!
val parsedMap = Constants.HOCON_MAPPER.readValue<Map<Int, String>>("""{ 1 = "abc" }""")
println(parsedMap)
Output: {1=abc}
val parsedMap = Constants.HOCON_MAPPER.readValue<Map<Int, String>>("""{ 0 = "abc" }""")
println(parsedMap)
Output:
Exception in thread "main" com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.LinkedHashMap` out of START_ARRAY token
at [Source: UNKNOWN; line: -1, column: -1]
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1343)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1139)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1093)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer._deserializeFromEmpty(StdDeserializer.java:600)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:360)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:29)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3023)
at net.perfectdreams.loritta.QuirkyStuffKt.main(QuirkyStuff.kt:63)
at net.perfectdreams.loritta.QuirkyStuffKt.main(QuirkyStuff.kt)
This happens even if the Map
is another type (Example: Map<String, String>
)
This does NOT happen when parsing with lightbend/config:
val conf = ConfigFactory.parseString("""{ 0 = "abc" }""")
println(conf)
Output: Config(SimpleConfigObject({"0":"abc"}))
Currently calling getTokenLocation()
on a HoconTreeTraversingParser
object returns JsonLocation.NA
, which is more or less valid, as there is no JSON location as the input isn't JSON.
Yet for some use cases it does make sense to have access to a location and even the underlying ConfigOrigin
object. Since the parser has access to this, it would be possible to implement getTokenLocation()
by returning a subclass of JsonLocation
that fills the line number field and source object (which are the only things available from ConfigOrigin
) and provide access to the underlying ConfigOrigin
.
A concrete use case for this is implementing a custom deserializer for Duration objects using the same code that TypeSafe Config uses for parsing the duration. This requires a ConfigOrigin
. The custom deserialier could attempt to cast the JsonLocation
to our own subclass and have access to the origin that way.
I'd be happy to provide a PR that implements this if it is a good idea.
The README.md also has wrong maven coordinates.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.