scala - Validate Datatype of Json Nodes (Jackson) -
i using jackson parsing parse json , saving hbase. prior save have validate datatype of nodes against list of datatypes mysql. following approach:
def validatenode(node:jsonnode, datatype : string) :any = { val nodevalue = node.tostring() datatype.tolowercase() match { case "double" ⇒ { try{ d.todouble } catch{ } } case "int" ⇒try { node.getvalueasint } catch{} case "string" ⇒ try{ node.gettextvalue }catch{} } }
which looks ugly me.
a) catching exceptions in every case block see whether datatype correct.
can suggests me elegant code this?
further, have handle datatypes array
, vector
too. eg : jsonnode
{"a":[[1,2],[2,4],[4,5]]} (==>vector of integer) .
Comments
Post a Comment