简体   繁体   中英

How to convert JsonNode to Date using Java 8 function

Having a common interface with a method signature as below.

Function

for long it is implemented as below

Function<JsonNode, Long> getMapping ()
 {
        return JsonNode::longValue;

 }

How this can be implemented for JsnonNode to Date .There is no direct api to get Date from JsonNode. JsonNode has a number and it is converted to Date as blow. Date d = new Date(1220227200L * 1000). Would like to know how to do that conversion in the below method

Function<JsonNode, Date> getMapping ()
{
}

Just do your calculation in a lambda expression:

Function<JsonNode, Date> getMapping ()
{
    return node -> new Date(node.longValue() * 1000);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM