JiBX: How can I use interfaces in my code?

How can I use my interfaces in classes with which I want to use JiBX binding?

Example: I have this very simple model in java:

public interface A {
    B getB();
    void setB(B b);
}

public interface B {
    String getData();
    void setData(String data);
}

public class AImpl implements A {
    B b;

    @Override
    public B getB() {
        return b;
    }

    @Override
    public void setB(B b) {
        this.b = b;     
    }
}

public class BImpl implements B {
    private String data;
    @Override
    public String getData() {
        return data;
    }

    @Override
    public void setData(String data) {
        this.data = data;
    }
}

And this required document:

<binding>
<mapping name="A"
         class="com.test.AImpl">
    <structure name="B" usage="optional" get-method="getB" set-method="setB"/>
</mapping>
<mapping name="B"
         class="com.test.BImpl">
    <value name="data" set-method="setData" get-method="getData" usage="optional"/>
</mapping>
</binding>

When I try to run my code, I get this exception:

java.lang.ClassFormatError: method in class com / test / B has illegal modifiers: 0x1001

I tried using 'abstract = "true"' for both mappings, only to get this exception:

... caused by: org.jibx.runtime.JiBXException: Unable to access required information for class com.test.A Make sure that the binding was compiled ...

, , , AImpl BImpl B BImpl getter return, BImpl. , .

? , ( , JiBX ) - .

? JiBX ( , ?)

, " AbstractB", , .

+3
2

"create-type" , JiBX bean, . . , JiBX java.util.HashSet java.util.Set. , , - . :

<mapping class="com.mypackage.AImpl" name="A">
  <structure get-method="getB" set-method="setB" create-type="com.mypackage.BImpl">
    ...
  </structure>
  ...
</mapping>

JiBX no-arg B. factory /, . . .

+4

binding.dtd - , , : http://jibx.cvs .sourceforge.net/ViewVC//JiBX/ ​​//binding.dtd. - (c:\binding.dtd, ). :

<binding xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file://jibx/binding.dtd">

://jibx/binding.dtd, binding.dtd .

, - , xml /dtds, " , ". , , /dtd xml - , .
.

0

Source: https://habr.com/ru/post/1710265/


All Articles