spring integration - ClassCastException: com.fasterxml.jackson.databind.node.MissingNode cannot be cast to com.fasterxml.jackson.databind.node.Arraynode -
i have reader maps data instagram system. when performing junit test ran classcastexception. test class has following code:
public class instagramtojsonmappertest extends abstractmappertest { private instagrammapper instagrammapper; private boolean printresult = true; @before public void setup() { super.setup(); instagrammapper = new instagrammapper(128); } private void comparejson(string unmapped, string mapped) throws exception { jsonnode unmappedjson = loadjson(unmapped); jsonnode mappedjson = loadjson(mapped); message<jsonnode> msg = messagebuilder.withpayload(unmappedjson).build(); message<jsonnode> resultmsg = instagrammapper.map(msg); jsonnode result = resultmsg.getpayload(); if(printresult) { system.out.println("processed: " + result); system.out.println("expected: " + mappedjson.tostring()); } assert.asserttrue(jacksonutils.equals(result, mappedjson)); } @test public void testphoto() throws exception { comparejson("/mapping/test.json", "/mapping/test_mapped.json"); } }
the error because of line in mapper:
string[] branches = jacksonutils.toarray((arraynode) extractor.extract("contentbranch")); if(branches.length == 1) { abc.put("contentbranch", branches[0]); } else { abc.set("contentbranch", jacksonutils.arraytoarraynode(branches)); }
my problem is, dont know change. should change mapper code or code in test file. error is:
classcastexception: com.fasterxml.jackson.databind.node.missingnode cannot cast com.fasterxml.jackson.databind.node.arraynode
you need use jsonnode node = extractor.extract("contentbranch")
, test actual node type returned.
in case, getting missingnode
can't cast arraynode
.
if (node instanceof arraynode) {...} else {...}
Comments
Post a Comment