Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property parser to make querying the properties easier #6

Open
andrewtarry opened this issue Mar 2, 2020 · 0 comments · May be fixed by #12
Open

Property parser to make querying the properties easier #6

andrewtarry opened this issue Mar 2, 2020 · 0 comments · May be fixed by #12
Labels
enhancement New feature or request

Comments

@andrewtarry
Copy link

andrewtarry commented Mar 2, 2020

In order to extract a series of nested properties, we need to create a complex series of calls. If we had a structure like this:

{
    "a": {
         "objectValue": {
             "stringValue": "value"
            } 
    }
}

In order to get the value we would need to do something like this

class Example {

    String getValue(PropertyHoldingEntity entity) {
        PropertyCollection propertyCollection = entity.getProperties();

        Optional<Property> subPropertyA = propertyCollection.getObjectByKey("a", Property.class);
        Optional<Property> valueA = subPropertyA.flatMap(p -> p.getObjectValue(Property.class));
        Optional<String> stringValue = valueA.flatMap(Property::getStringValue);
        
        return stringValue.orElse("");
    }
}

A better solution would be to allow json style path to be mapped to it.

public interface PropertyMapper {
    
    Optional<String> getStringValue(PropertyHoldingEntity entity, String path);
}
class Example {

    String getValue(PropertyHoldingEntity entity) {
        PropertyMapper propertyMapper = new PropertyMapper();

        return propertyMapper.getStringValue(entity, "a.object.string").orElse("");
    }
}
@andrewtarry andrewtarry added the enhancement New feature or request label Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant