cyberborean / rdfbeans

Java persistence with RDF
Other
11 stars 12 forks source link

Datatype character is missing in DefaultDataTypeMapper #37

Closed twallmey closed 5 years ago

twallmey commented 5 years ago

Hi,

I've just recognized that no mapping is defined for datatype character. In case I try to set value of type char by calling the corresponding setter of my bean I get a RDFBeanException saying:

aused by: org.cyberborean.rdfbeans.exceptions.RDFBeanException: Unexpected value to set: I at org.cyberborean.rdfbeans.proxy.RDFBeanDelegator.toRdf(RDFBeanDelegator.java:506) at org.cyberborean.rdfbeans.proxy.RDFBeanDelegator.setValue(RDFBeanDelegator.java:414) at org.cyberborean.rdfbeans.proxy.RDFBeanDelegator.invoke(RDFBeanDelegator.java:131) ... 66 common frames omitted

For this reason I suggest to add an additional mapping within class DefaultDataTypeMappern (object DATATYPE_MAP). Would it be possible to map Java class character to XMLSchema.String ?

Best,

Thorben

cyberborean commented 5 years ago

No, we cannot simply map Character to xsd:string, as it's already taken by String. Imagine, you have

char charValue;

@RDF("urn:uri:test/datatype/char")
public char getCharValue() {
    return charValue;
}
public void setCharValue(char charValue) {
    this.charValue = charValue;
}

If the charValue is represented with a plain (i.e. xsd:string) literal, RDFBeans will look for a setCharValue(String) method to unmarshall the object and will fail with the "no method exists" exception.

We need to declare our custom RDF datatype to represent Java char values.