0

I am trying to use the ParserUtil to deserialize and serialize Xively data objects such as Datastream and Datapoint.

While the toJson function works perfectly, I can't get toConnectedObject and toConnectedObjects function working.

The following is the code excerpt and corresponding log.

String jsonDP=ParserUtil.toJson(false, dp);

Datapoint dpNew=ParserUtil.toConnectedObject(jsonDP, Datapoint.class);

LOGGER.debug(ParserUtil.toJson(false, dpNew));

Log:

2013-08-28 11:45:31,348 2064  DEBUG [ParserUtil.java: 136] (main:) Parsing models to json
2013-08-28 11:45:31,376 2092  DEBUG [ParserUtil.java: 187] (main:) Parsed json from     models: {"datapoints":[{"at":"2012-02-19T00:00:02.283064Z","value":"261"}]}
2013-08-28 11:45:31,376 2092  DEBUG [ParserUtil.java: 221] (main:) Parsing string to object: {"datapoints":[{"at":"2012-02-19T00:00:02.283064Z","value":"261"}]}
2013-08-28 11:45:31,377 2093  DEBUG [ParserUtil.java: 136] (main:) Parsing models to json
2013-08-28 11:45:31,377 2093  DEBUG [ParserUtil.java: 187] (main:) Parsed json from models: {"datapoints":[{"value":null}]}
2013-08-28 11:45:31,377 2093  DEBUG [XivelyHelper.java: 295] (main:) {"datapoints":[{"value":null}]}

The result of toConnectedObject(jsonDP, Datapoint.class), newDP object, has both fields "at" and "value" set to null.

I tried the same procedure with Datastream object all the fields are null as well.

AlexVogel
  • 10,601
  • 10
  • 61
  • 71

1 Answers1

0

In this case the datapoints are in an array with just one element.

errordeveloper
  • 6,716
  • 6
  • 41
  • 54
  • Hi errordeveloper, I have tested with the following different json inputs it seems that the problem is with the root wrapping "datapoints". The following string works with toConnectObject():"{"at":"2012-02-19T00:00:02.283064Z","value":"261"}" but toConnectObjects() with the string in my original post only returns a one-object collection where the only Datapoint object has all fields set to null. I am still trying different configurations and will comeback with more info. – Feischi Aug 28 '13 at 14:50
  • 1
    ok, i got it, by checking the test cases. the two operations are not exactly opposite of each other. when converting to json, root element is added, while when parsing, root is not included. this applies to all domain objects. – Feischi Aug 29 '13 at 12:45