VMware Cloud Community
ngaic
Contributor
Contributor

Is there serializer/deserializer for object type Any

Hi all.

When I call orchestrator web service I need to sent WorkflowTokenAttribute that is type "any". One of return values that I get with getWorkflowTokenResult is type "any" also.

In the end I am manualy creating value from my json object and I and up with this. That works well but it is inpractical.

attr.name = "tvojObj";

attr.type = "Any";

attr.value = "Array##{#Properties##[#attr2#=#string#drugi#+#attr1#=#string#prvi#+#arrAttr1#=#Array##{#Properties##[#drugi#=#string#1-2#+#treci#=#string#1-3#+#prvi#=#string#1-1#]##;#Properties##[#drugi#=#string#2-2#+#treci#=#string#2-3#+#prvi#=#string#2-1#]##}##]##}#";

Is there some serializer JSON object to type any

{

  "url": "http://example.com/",

  "id": 26,

  "ipList":

  [{

    "ip": "someIP",

    "port": "Some port"

  }]

}

to

Array##{#Properties##[#url#=#string#http://example.com/#+#id#=#noumber#26#+#ipList#=#Array##{#Properties##[#ip#=#string#someIP#+#port#=#string#Some port#]##}##]##}#

Reply
0 Kudos
1 Reply
iiliev
VMware Employee
VMware Employee

Hi,

First, a couple of remarks.

  • SOAP API is deprecated and will be removed in upcoming vRO 7.0, so you may want to look into REST API
  • Strictly speaking, there are no objects of 'any' type. Eg. when a workflow is defined as having an input parameter of type any, when you call it it actually pass an object of some concrete type.

Now to your question. There is a class ch.dunes.model.type.AnyConvertor (in o11n-model) that could be useful. The following sample code should work

AnyConvertor conv = new AnyConvertor();

String value = "Array##{#Properties##[#attr2#=#string#drugi#+#attr1#=#string#prvi#+#arrAttr1#=#Array##{#Properties##[#drugi#=#string#1-2#+#treci#=#string#1-3#+#prvi#=#string#1-1#]##;#Properties##[#drugi#=#string#2-2#+#treci#=#string#2-3#+#prvi#=#string#2-1#]##}##]##}#";

try {

    // convert string representation to object

    Object obj = conv.toObject(value, null, ConvertorContext.SERVER_CONTEXT);

    if (obj != null) {

      StringBuffer buffer = new StringBuffer();

      // convert object back to string representation

      conv.toString(buffer, obj, ConvertorContext.SERVER_CONTEXT);

      String s = buffer.toString();

    }

} catch (ConvertorException e) {

  e.printStackTrace();

}

Not sure which class you are using for JSON objects so you may need to write some simple adaptor code to provide mapping between your JSON objects and the objects returned by AnyConvertor.

Reply
0 Kudos