fatsecret/fatsecret4j

brand_name not parsed

JulianBissekkou opened this issue ยท 2 comments

First of all, great job with the simple API. It's a joy using it and setting things up was way easier than other food APIs out there! ๐Ÿ‘

I am using version 2.0 of the library and I am calling the searchFood endpoint.
It looks like the returned result of CompactFood does not contain the brandName meaning that it's always null.

This is my proposed change in FoodUtility.parseCompactFoodJsonObject:

	public static CompactFood parseCompactFoodFromJSONObject(JSONObject json) {
		String name = json.getString("food_name");
		String url = json.getString("food_url");
		String type = json.getString("food_type");
		String description = json.getString("food_description");
		Long id = Long.parseLong(json.getString("food_id"));
                String brandName = type == "Brand" ? json.getString("brand_name") : null; // <----

		CompactFood food = new CompactFood();
		
		food.setName(name);
		food.setUrl(url);
		food.setType(type);
		food.setDescription(description);
		food.setId(id);
                food.setBrandName(brandName); // <----
		
		return food;
	}

Keep in mind that it's been a while since I last wrote some Java code ๐Ÿ˜… , but I think it's clear what I am trying to do.
Would this change work, and if so, can you provide a fix asap?

Here is the pull request for the described issue:
#16

Closing this since the repo is not maintained anymore and I don't want to have this annoying issue on my GitHub dashboard ๐Ÿ‘