java - What syntax would I use to have my program disregard underscores, punctuation, and all other camelcase etc -
i using jackson library. have added in dependencies.
here syntax have used far, have passed in object method called result.
private void getsamplefromjson(list<sampleprojectdto> result) throws jsonparseexception, jsonmappingexception, ioexception { url url = this.getclass().getresource("/test.json"); file jsonfile = new file(url.getfile()); system.out.println("full path of file: " + jsonfile); objectmapper mapper = new objectmapper(); inputstream = test_project.class.getresourceasstream("/test.json"); sampledto testobj = mapper.readvalue(is, sampledto.class); system.out.println(testobj.getcreatedbyurl()); }
now file reading, file text file json in it. problem lot of variables , things in file have underscores, , in camel case, , causing program not run. can not have change entire json file, there programming method or statement can put in have ignore these punctuations , camel case , make nice , snake case method able work , program?
i might not understand concrete problem have, mapping pojo fields json properties can done follows.
you either have use jsonproperty annotation:
class sampledto{ @jsonproperty("first_name") // property name json protected string firstname; protected string getfirstname(){return firstname;} } or configure objectmapper propertynamingstrategy:
mapper.setpropertynamingstrategy( propertynamingstrategy.camel_case_to_lower_case_with_underscores); you can implement own propertynamingstrategy if want, it's you.
Comments
Post a Comment