2

I am trying out Complexible Pinto for mapping between Java POJOs and RDF. In one of my evaluation tests, I have a derived property that should not appear in the output triples, however it seems that all JavaBean getters are automatically included in the output with a generated property resource. How can I suppress this without mangling the method name? Similar frameworks typically have some kind of @Ignore annotation or an an ignore annotation parameter, but I do not see one in Pinto.

I can suppress this by mangling the method name (e.g. xgetNameLength()), but I would prefer not to do it that way, since that would be ugly.


Code:

I create a Java POJO that has a derived property that should not be mapped, and convert it to triples using Pinto.

package pintoeval;

import org.openrdf.model.Graph;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
import org.openrdf.model.impl.URIImpl;
import org.openrdf.rio.RDFFormat;
import org.openrdf.rio.RDFWriter;
import org.openrdf.rio.Rio;

import com.complexible.pinto.Identifiable;
import com.complexible.pinto.RDFMapper;
import com.complexible.pinto.annotations.RdfProperty;
import com.complexible.pinto.annotations.RdfsClass;

public class PintoStackOverflowQuestion {

    @RdfsClass("http://www.example.com/person")
    public static class Person implements Identifiable {
        private Resource id;
        private String name;


        @Override
        public Resource id() {
            return id;
        }

        @Override
        public void id(Resource arg0) {
            id = arg0;
        }

        public String getName() {
            return name;
        }

        @RdfProperty("http://www.example.com/personName")
        public void setName(String name) {
            this.name = name;
        }

        /*
         * This is directly derived from another value, so it should not be stored.
         */
        public int getNameLength() {
            return name.length();
        }
    }

    public static void main(String[] args) throws Exception {
        Person person = new Person();
        person.id(new URIImpl("http://www.example.com/person/Larry0384"));
        person.setName("Larry");

        Graph aGraph = RDFMapper.create().writeValue(person);

        RDFWriter writer = Rio.createWriter(RDFFormat.NTRIPLES, System.out);
        writer.startRDF();
        for (Statement s : aGraph) {
            writer.handleStatement(s);
        }
        writer.endRDF();
    }
}

Output:

The derived value is mapped with a generated property. I would like to exclude it, so only two triples would be created.

<http://www.example.com/person/Larry0384> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/person> .
<http://www.example.com/person/Larry0384> <tag:complexible:pinto:nameLength> "5"^^<http://www.w3.org/2001/XMLSchema#int> .
<http://www.example.com/person/Larry0384> <http://www.example.com/personName> "Larry"^^<http://www.w3.org/2001/XMLSchema#string> .
Kaypro II
  • 3,210
  • 8
  • 30
  • 41
  • Try `@RdfProperty(null)` - does that work? – Bohemian Jan 13 '16 at 21:02
  • I tried that, but I get this compile error `The value for annotation attribute RdfProperty.value must be a constant expression`. I get the same error if I define set some actual string constant to null and use that instead. – Kaypro II Jan 13 '16 at 21:07
  • Try `@RdfProperty("")` instead – Bohemian Jan 13 '16 at 21:09
  • You could also try creating a setter for length (that throws an `UnsupportedOperationException`) that does *not* have a `@RdfProperty` annotation – Bohemian Jan 13 '16 at 21:11
  • Still doesn't work. I had already tried some straightforward potential magic values, and none of them worked. Looking at the one place in the code where that value is read, both of the values you suggested are explicitly equivalent to no annotation. – Kaypro II Jan 13 '16 at 21:15
  • I have no idea if this would work (not having tried Pinto myself), but: have you tried declaring the member variable transient? – Jeen Broekstra Jan 13 '16 at 21:57
  • There's no field to declare transient: it's picking up on the getter method. Pinto does not seem to automatically pick up fields anyway. – Kaypro II Jan 13 '16 at 22:26
  • Ah right, should've looked closer, sorry. – Jeen Broekstra Jan 13 '16 at 23:01
  • Had a quick glance at the code base and it doesn't seem like they currently offer anything for this. Your best course would be to log a feature request. – Jeen Broekstra Jan 14 '16 at 01:26

1 Answers1

2

As Jeen suggested, Pinto doesn't current offer this capability. But this was on my mental todo list, so I created an issue for this.

Michael
  • 4,858
  • 19
  • 32