Nooul / spring-boot-rest-api-helpers

Java Spring REST API helpers for quick query building through JSON inspired by react-admin and offering an alternative to RSQL / FIQL
MIT License
36 stars 21 forks source link

Duplicated map keys on snake case #20

Open danielsobrado opened 2 years ago

danielsobrado commented 2 years ago

Hi,

The following function on FilterService is creating duplicated maps when converting snake case to camel case, and both the snake case and camel case remain in the map, causing it to fail:

    private HashMap<String, Object> convertToCamelCase(HashMap<String, Object> snakeCaseMap) {
        Set<String> keys = snakeCaseMap.keySet();
        HashMap<String, Object> camelCaseMap = new HashMap<>(snakeCaseMap);
        for (String key : keys) {
            Object val = snakeCaseMap.get(key);
            camelCaseMap.put(convertToCamelCase(key), val);
-->            camelCaseMap.remove(key);
        }
        return camelCaseMap;
    }

I included camelCaseMap.remove(key); to properly replace the key instead of adding a new one.

zifnab87 commented 2 years ago

@danielsobrado good point - can you please make a pull request so I can merge it? Thanks

danielsobrado commented 2 years ago

Sure, let me create a test case and a PR.