-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom deserialization for class Queries(val pairs: Map[String, Seq[String]]) #18
Comments
This seems to be working. Do you've any suggestions to make this better?
|
I'm not sure I understand the YAML you are expecting for that class. Can you give an example of an YAML object you need to deserialize into a The most common format for your class is something like: pairs:
key1:
- a
- b
key2:
- c
- d In that case, and if you can turn your class into a case class, your implicit val queriesYamlFormat = yamlFormat1(Queries) Looking at your last key1:
- a
- b
key2:
- c
- d In that case, you can have: implicit object QueriesYamlFormat extends YamlFormat[Queries] {
override def write(obj: Queries): YamlValue = ???
override def read(yaml: YamlValue): Queries =
Queries(yaml.convertTo[Map[String, Seq[String]]])
} You can adapt this last format to modify the map after deserializing, if required by your domain. |
@jcazevedo wrote:
This doesn't work when there's no field called
|
How do I deserialize this class?
class Queries(val pairs: Map[String, Seq[String]])
I've something along the lines of the following:
But not sure how to interpret
m
. There doesn't seem to be aYamlMap
class to use.The text was updated successfully, but these errors were encountered: