Map<String, Object> infos = new HashMap<>(2); Optional.ofNullable(country.getIsoCode()).ifPresent(i -> infos.put("code", i)); Optional.ofNullable(country.getNames().get(locale)).ifPresent(i -> infos.put("name", i)); if(infos.size() > 0) { informations.put("country", infos); Map<String, Object> infos = new HashMap<>(2); Optional.ofNullable(represented_country.getIsoCode()).ifPresent(i -> infos.put("code", i)); Optional.ofNullable(represented_country.getNames().get(locale)).ifPresent(i -> infos.put("name", i)); if(infos.size() > 0) { informations.put("represented_country", infos); Map<String, Object> infos = new HashMap<>(2); Optional.ofNullable(registred_country.getIsoCode()).ifPresent(i -> infos.put("code", i)); Optional.ofNullable(registred_country.getNames().get(locale)).ifPresent(i -> infos.put("name", i)); if(infos.size() > 0) { informations.put("registred_country", infos);