Created
June 11, 2013 15:59
-
-
Save fdescamps/5758120 to your computer and use it in GitHub Desktop.
Able to read complex json, when you json block contains alternatively an object or an array without predictibility.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Reads only sector with sequence of industries | |
| implicit val secteurReads: Reads[Secteur] = ( | |
| ( __ \ "name" ).read[String] ~ | |
| ( __ \ "industry" ).lazyRead( play.api.libs.json.Reads.seq[Industrie] ) | |
| )( Secteur ) | |
| //Reads sector with sequence of industries or an only object industry | |
| implicit val secteurReads: Reads[Secteur] = ( | |
| ( __ \ "name" ).read[String] ~ | |
| ( __ \ "industry" ).read( Reads.seq[Industrie] or Reads.of[Industrie].map( industrie => Seq(industrie) ) ) | |
| )( Secteur ) | |
| // able to Read sector with sequence of industries or sector with an only object industry | |
| implicit val secteurReads: Reads[Secteur] = ( | |
| ( __ \ "name" ).read[String] ~ | |
| ( __ \ "industry" ).read( Reads.seq[Industrie] or Reads.of[Industrie].map( industrie => Seq(industrie) ) ) | |
| )( Secteur ) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Able to read :
"sector":[ {
"name":"Basic Materials",
"industry":[
{
"id":"112",
"name":"Agricultural Chemicals"
}, ...
]
...
Or
"industry": {
"id":"112",
"name":"Agricultural Chemicals"
}