Custom json input validation in spring boot

Viewed 19

I have nested input JSON. In the nested input JSON, there is a common JSONObject. i.e "inch and fraction" or "feet, inch and fraction" which is present in multiple places. I have to validate the entire input JSON in such a way that if there is a sum of the "inch and fraction" value or the sum of the "feet, inch and fraction" value is 0, then I have to throw an exception saying invalid inch and fraction data or feet inch fraction data.

Input JSON

 {
       "key1": 1,
       "key2": "xxxxxxxxxxxx",
       "key3": "xxxxxxxxx",
       "key4": "",
       "key5": "",
       "key6": {              
           "feet": 0,
           "inch": 1,
           "fraction": 0
       },
       "key7": "",
       "key8": {              
           "inch": 0,
           "fraction": 0
       },
       "key9": {              
           "inch": 1,
           "fraction": 1
       },
       "key10": {              
           "inch": 1,
           "fraction": 1
       },
       "key11": {              
           "inch": 1,
           "fraction": 1
       },
       "key12": {
           "key13": "",
           "key14": {                   
               "inch": 1,
               "fraction": 1
           },
           "key15": {                  
               "inch": 1,
               "fraction": 1
           }
       },
       "key16": {
           "key17": "",
           "key18": {                  
               "inch": 1,
               "fraction": 1
           },
           "key19": {                  
               "inch": 1,
               "fraction": 1
           }
       },
       "key20": "",
       "key21": "",
       "key22": "Welded",
       "key23": "Welded",
       "key24": {               
           "inch": 1,
           "fraction": 1
       },
       "key25": {               
           "inch": 1,
           "fraction": 1
       },
       "key26": {               
           "feet": 0,
           "inch": 1,
           "fraction": 0
       }
   
   }

My Model Classes

   public class ShopstandardInputJSON {
    private float key1;
     private String key2;
     private String key3;
     private String key4;
     private String key5;
     private FeetInchFraction key6;
     private String key7;
     private InchFraction key8;
     private InchFraction key9;
     private InchFraction key10;
     private InchFraction key11;
     private Key12 key12;
     private Key16 key16;
     private String key20;
     private String key21;
     private String key22;
     private String key23;
     private InchFraction key24;
     private InchFraction key25;
     private FeetInchFraction key26;
}

public class InchFraction { 
    private int inch;
    private float fraction;
}

public class FeetInchFraction { 
    private int feet;
    private int inch;
    private float fraction;
}
0 Answers
Related