Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mirrors
biopet.biopet
Commits
a6ed777d
Commit
a6ed777d
authored
Nov 08, 2014
by
Peter van 't Hof
Browse files
Added mapToJson method
parent
323c6e1e
Changes
1
Hide whitespace changes
Inline
Side-by-side
biopet-framework/src/main/scala/nl/lumc/sasc/biopet/core/config/Config.scala
View file @
a6ed777d
...
...
@@ -197,4 +197,28 @@ object Config {
return
None
}
}
def
mapToJson
(
map
:
Map
[
String
,
Any
])
:
Json
=
{
map
.
foldLeft
(
jEmptyObject
)((
acc
,
kv
)
=>
(
kv
.
_1
:=
{
kv
.
_2
match
{
case
m
:
Map
[
_
,
_
]
=>
mapToJson
(
m
.
map
(
m
=>
m
.
_1
.
toString
->
anyToJson
(
m
.
_2
)))
case
_
=>
anyToJson
(
kv
.
_2
)
}
})
->:
acc
)
}
def
anyToJson
(
any
:
Any
)
:
Json
=
{
any
match
{
case
j
:
Json
=>
j
case
m
:
Map
[
_
,
_
]
=>
mapToJson
(
m
.
map
(
m
=>
m
.
_1
.
toString
->
anyToJson
(
m
.
_2
)))
case
l
:
List
[
_
]
=>
Json
.
array
(
l
.
map
(
anyToJson
(
_
))
:
_
*
)
case
n
:
Int
=>
Json
.
jNumberOrString
(
n
)
case
n
:
Double
=>
Json
.
jNumberOrString
(
n
)
case
n
:
Long
=>
Json
.
jNumberOrString
(
n
)
case
n
:
Short
=>
Json
.
jNumberOrString
(
n
)
case
n
:
Float
=>
Json
.
jNumberOrString
(
n
)
case
n
:
Byte
=>
Json
.
jNumberOrString
(
n
)
case
_
=>
jString
(
any
.
toString
)
}
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment