0

I am using ObjectUtils.isEmpty() as generic to check for the null and empty fields.It was working fine for the term like:

MyClass class = new MyClass()
class.setName(null);

if (!ObjectUtils.isEmpty(class.getName)) {
    return "Name";
}

But it is not working , when am trying it for the Object as below:

Object activatedDate = jsonObject.getJSONArray("records")
          .getJSONObject(i).get("ActivatedDate");
return ObjectUtils.isEmpty(activatedDate) ? null : "hello";

and My json is:

[
  {
    "LastModifiedDate": "2018-05-23T10:58:18.000+0000",
    "Order_Submission_Outcome__c": "test",
    "Number_of_Orders__c": 0,
    "Sales_Code__c": null,
    "Opportunity__c": "FERERR",
    "Contract_Type__c": "EZ Order Form",
    "StatusCode": "Draft",
    "CreatedDate": "2018-05-23T10:56:22.000+0000",
    "Id": "FERERR",
    "ActivatedDate": null,
    "Contract_Status__c": "ACTIVE",
    "Opportunity_Act_Total_Lines__c": 1
  }
]

But it always returns hello even though the object activatedDate is null. What is the problem?

kaviya .P
  • 469
  • 3
  • 11
  • 27
  • 2
    *"But it always returns hello even though the object activatedDate is null."* That can't be the case. Please debug your code to see what's actually going on. – Max Vollmer Jun 11 '18 at 07:14
  • @buræquete yes that is org.springframework.util.ObjectUtils.I already debug the code , that the activatedDate was null only.Actually I need to convert that object to date, I can't cast "null" to date right..So am checking for the null first and then trying to convert it. – kaviya .P Jun 11 '18 at 07:18
  • Can you post the `JSON` that you are parsing? – Antho Christen Jun 11 '18 at 07:20
  • @anchreg yes I posted my json. – kaviya .P Jun 11 '18 at 07:29
  • the code you've posted seems to work fine. Please debug your actual code – Antho Christen Jun 11 '18 at 07:43
  • Did you notice, how `class` was highlighted in you code snippet three times? You can’t name a variable “`class`”, as that’s a reserved keyword. So it’s hard to believe that this code snippet “was working fine”… – Holger Jun 11 '18 at 08:47
  • @anchreg Yes am debugging , still the same problem:-( – kaviya .P Jun 11 '18 at 09:00

1 Answers1

0

In JPA QL if you want to call a database function it has to be done like this:

function(‘FUNC_NAME’, param1, param2,...)
Strelok
  • 50,229
  • 9
  • 102
  • 115