[ https://issues.apache.org/jira/browse/GEODE-226?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17216452#comment-17216452 ]
rickberon commented on GEODE-226: --------------------------------- The JSON specification does not specify a format for exchanging dates which is why there are so many different ways to do it. The problem with dates in JSON and JavaScript in general – is that there's no equivalent literal representation for dates. In JavaScript/[jQuery|http://net-informations.com/jq/iq/jdate.htm] following Date constructor straight away converts the milliseconds since 1970 to Date as follows: var jsonDate = new Date(1297246301973); Then let's convert it to js format: var date = new Date(parseInt(jsonDate.substr(6))); The substr() function takes out the /Date( part, and the parseInt() function gets the integer and ignores the )/ at the end. The resulting number is passed into the Date constructor . For ISO-8601 formatted JSON dates, just pass the string into the Date constructor: var date = new Date(jsonDate); > JSON seems to lose time portion on getObject > -------------------------------------------- > > Key: GEODE-226 > URL: https://issues.apache.org/jira/browse/GEODE-226 > Project: Geode > Issue Type: Bug > Components: serialization > Reporter: Konstantin Ignatyev > Assignee: Hitesh Khamesra > Priority: Major > Labels: SmallFeature > > com.gemstone.gemfire.pdx.internal.PdxInstanceImpl#getObject > Date format, in the JSON land it is pretty much settled to be ISO 8661 > https://weblog.west-wind.com/posts/2014/Jan/06/JavaScript-JSON-Date-Parsing-and-real-Dates > > It would be nice to be able to have Geode’s JSON standard compliant, or have > this configurable. Otherwise the we will be loosing time portion of date-s > public Object getObject() { > if (getPdxType().getNoDomainClass()) { > //In case of Developer Rest APIs, All PdxInstances converted from Json > will have a className =__GEMFIRE_JSON. > //Following code added to convert Json/PdxInstance into the Java object. > if(this.getClassName().equals("__GEMFIRE_JSON")){ > > //introspect the JSON, does the @type meta-data exist. > String className = extractTypeMetaData(); > > if(StringUtils.hasText(className)) { > try { > ObjectMapper mapper = new ObjectMapper(); > mapper.setDateFormat(new SimpleDateFormat("MM/dd/yyyy")); > mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, > false); > > mapper.configure(com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, > true); > String JSON = JSONFormatter.toJSON(this); > Object classInstance = mapper.readValue(JSON, > ClassPathLoader.getLatest().forName(className)); > return classInstance; > }catch(Exception e){ > throw new PdxSerializationException("Could not deserialize as java > class type could not resolved", e); > } > } > } > return this; > } > Also this method is not that performant, please see #225 -- This message was sent by Atlassian Jira (v8.3.4#803005)