0

I want to convert JSON to java my json

var eateryRatingFactory = function() {
  var self = this;
  self.dineInMenu = [{
    header: "Food",
    items: [{
      name: "Quality",
      id: '1',
      rating: '0'
    },.....so on ]
  },......so on ];
self.deliveryMenu = //some values same as beloew
};

my java class

    public class EateryRatingAdapter {

    public List<Ratings> dineInMenu;
    public List<Ratings> deliveryMenu;
    //setters and getters   

    public class Ratings{
        public String header;
        public List<Item> items;
        //setters and getters
        public class Item{
            public String name;
            public String id;
            public String rating;
            //setters and getters
        }
    }

}

while i'm getting the JSON at Request body , it is giving 400 bad request mean syntax mistake can u guys help this out

Venkatesh
  • 17
  • 3

1 Answers1

0

Use Object Mapper

ObjectMapper mapper = new ObjectMapper();

// Your JSON should cater your class

String jsonString = "{"header": "Food"  , ................}"; 

//JSON from String to Object

**Ratings obj = mapper.readValue(jsonString, Ratings.class)**
msp
  • 3,272
  • 7
  • 37
  • 49