Create Search Attribute from json

Hi

Need pointer on how to create SearchAttributes object from json String payload. I have the following search attributes. Is there a utility method for getting a SearchAttributes object from the same.

Need the same to Mock SeachAttribute in unit test.

Thanks in advance
Best Regards
Krishnendu

“indexed_fields {\r\n”

  • " key: "MODN_ACTIVITY_LIST"\r\n"
  • " value {\r\n"
  • " metadata {\r\n"
  • " key: "encoding"\r\n"
  • " value: "json/plain"\r\n"
  • " }\r\n"
  • " metadata {\r\n"
  • " key: "type"\r\n"
  • " value: "Text"\r\n"
  • " }\r\n"
  • " data: "\"[{\\\"activityName\\\":\\\"SomeName\\\",\\\"activityId\\\":\\\"4f25c5fd-0bc3-3d6e-9d28-7b301a0d08b7\\\"}]\""\r\n"
  • " }\r\n"
  • “}\r\n”
  • “indexed_fields {\r\n”
  • " key: "MODN_SCHEDULER"\r\n"
  • " value {\r\n"
  • " metadata {\r\n"
  • " key: "encoding"\r\n"
  • " value: "json/plain"\r\n"
  • " }\r\n"
  • " metadata {\r\n"
  • " key: "type"\r\n"
  • " value: "Bool"\r\n"
  • " }\r\n"
  • " data: "false"\r\n"
  • " }\r\n"
  • “}\r\n”
  • “indexed_fields {\r\n”
  • " key: "MODN_SERVICE_AREA"\r\n"
  • " value {\r\n"
  • " metadata {\r\n"
  • " key: "encoding"\r\n"
  • " value: "json/plain"\r\n"
  • " }\r\n"
  • " metadata {\r\n"
  • " key: "type"\r\n"
  • " value: "Text"\r\n"
  • " }\r\n"
  • " data: "\"platform-services\""\r\n"
  • " }\r\n"
  • “}”

Was able to achieve the same using following:

String t=“[{"activityName":"SomeName","activityId":"4f25c5fd-0bc3-3d6e-9d28-7b301a0d08b7"}]”;

Payload.newBuilder().setData(ByteString.copyFromUtf8(t));

System.out.println(Payload.newBuilder().setData(ByteString.copyFromUtf8(t)));
SearchAttributes attrs=SearchAttributes.
newBuilder().putIndexedFields(“Test”,Payload.newBuilder().setData(ByteString.copyFromUtf8(t)).build()).build();

Thank you
Regards
Krishnendu

1 Like