0

I'm getting a java safety error and honestly if this was a house I was living in I'd be a little scared too.

obj is a JSONObject from the JSON-Simple library

      obj.put("ord.cancelled_by__c", replaceNull(String.valueOf(((JSONObject)(jsonobjresponseinfo.get("AuditLog"))).get("cancelledBy")), ""));

the auditlog object inside it has a field cancelled by. I would like to check that field for not null and if it is null then pass it "" instead

  private static String replaceNull(String value, String ifnull){
    return replaceNull(value, ifnull, value);
  }
  private static String replaceNull(String value, String ifnull, String ifnotnull){
    return value.isEmpty() ? ifnull : ifnotnull;
  }

to be honest I'm pretty sure this will work but there has to be a more elegant solution. Does anybody have an idea?

I'm recieving a type safety error for raw type hashmap on the put method

Thanks for reading

1 Answer 1

1

Probably you get this error because of your IDE settings. Normally this is a warning. But if you set an option like "treat warnings as error" in your IDE, your IDE complains this as an error. JSONObject class in json-simple library extends java.util.HashMap and does not define generics. So this type of warnings show up.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.