Error when updating an array element object using java rest client api

Found a solution based on this post

The solution is to convert your json object to a map using the Jackson ObjectMapper before adding it to the params map.

    final String updateElementScript = "for (int i=0; i < ctx._source.elements.length; i++) {if (ctx._source.elements[i].SerialNumber == params.sn) { ctx._source.elements[i] = params.newElement; }}";

    String json = "{\"OUI\":\"00D09E\", \"SerialNumber\":\"NEW00000001AB\"}";
    Map<String, Object> jsonMap = new ObjectMapper().readValue(json, HashMap.class);
    Map<String, Object> params = ImmutableMap.of(
    	"sn", "00000001AA"
    	"newElement", jsonMap);

    UpdateRequest request = new UpdateRequest().index("PlayerIndex").id("1");
                request.script(new Script(ScriptType.INLINE,
                        "painless",
                        updateElementScript,   
                        params));

    client.update(request, RequestOptions.DEFAULT);    // RestHighLevelClient