Hi All, May I know the right way to iterate throug...
# help
a
Hi All, May I know the right way to iterate through a list of objects and parse them in handlebar helper. Example for following
{{sortBy users 'address.city'}}
where user = {"name": "john", "address":{"city":"London","country":"ENG"},"age":36}, how to get the value of
address.city
from the object?
Copy code
public Object apply(List<?> list, Options options) throws IOException {
        if (list == null || list.isEmpty()) {
            return emptyList();
        } 
        final String sortBy = options.params[0].toString();
        final ArrayList<Object> resultList = new ArrayList<>(list)
        resultList.sort((o1, o2) -> {
            try {
                //How to get these values?
                String value1 = o1.get(property).asText();
                String value2 = o2.get(property).asText();

                return value1.compareTo(value2);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
        return resultList;
    }
l
If
user
is a json string could you parse the json into an object of your creation?
a
it could be any object in json string format