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

Generic predicates and functions should be able to dynamically deserialise JSON fields #67

Open
p013570 opened this issue Dec 4, 2017 · 1 comment
Labels
enhancement Improvement to existing functionality/feature
Milestone

Comments

@p013570
Copy link
Member

p013570 commented Dec 4, 2017

Currently if you deserialise:

{
    "class": "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan",
    "value": 1512381090096
}

it will throw an exception saying 1512381090096 is bigger than MAX integer. It should use Long by default.

When used in Gaffer, the Gaffer schema defines the class types for the IsMoreThan value field. We should allow users in Gaffer to write the above json and automatically deserialise the value field into a custom class, like a Date, without requiring the user to provide the class like:

{
    "class": "uk.gov.gchq.koryphe.impl.predicate.IsMoreThan",
    "value": {
       "java.util.Date": 1512381090096
    }
}

We have a method: InputValidator.isInputValid. This takes in classes and checks the predicate's field match the classes. If we pass in a Date class, then we should be able to convert the above long into a Date using JSON serialisation. For example, in the IsMoreThan class:

if (!controlValue.getClass().isAssignableFrom(arguments[0])) {
    final String json;
    try {
        json = JsonSerialiserUtil.serialise(controlValue);
        controlValue = (Comparable) JsonSerialiserUtil.deserialise(json, arguments[0]);
    } catch (final Exception e) {
        result.addError("Control value class " + controlValue.getClass().getName() + " is not compatible with the input type: " + arguments[0]);
    }
}

We could create an interface:

public void TypeResolver {
void resolveTypes(final Class<final Class<?>... arguments);
}

And for any classes that have jsonSubType annotations on fields implement it with something like the above code.

@p013570 p013570 added the enhancement Improvement to existing functionality/feature label Dec 4, 2017
m607123 added a commit that referenced this issue Dec 18, 2017
@m607123
Copy link
Contributor

m607123 commented Dec 18, 2017

Added a JsonSerialisiationUtil class in Koryphe core.
Created a TypeResolver interface, with method resolveTypes(final Class<?>... args), which should attempt to reserialise the predicate value(s).

@m607123 m607123 removed their assignment Dec 18, 2017
@n3101 n3101 added this to the v2_backlog milestone Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement to existing functionality/feature
Projects
None yet
Development

No branches or pull requests

3 participants