-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fixes issue when a Class of X contains a field with a List<X> then WireMarshaller recursively attempts to resolve X. closes #915 Co-authored-by: Jerry Shea <[email protected]>
- Loading branch information
Showing
5 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/test/java/net/openhft/chronicle/wire/recursive/Base.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.openhft.chronicle.wire.recursive; | ||
|
||
import net.openhft.chronicle.wire.AbstractEventCfg; | ||
|
||
public class Base extends AbstractEventCfg<Base> { | ||
private final String name; | ||
|
||
public Base(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String name() { | ||
return name; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/test/java/net/openhft/chronicle/wire/recursive/RecursiveTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package net.openhft.chronicle.wire.recursive; | ||
|
||
import net.openhft.chronicle.wire.WireMarshaller; | ||
import org.junit.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
/** | ||
* Test for recursion in the marshaller and fields. WIRE_MARSHALLER_CL.get should not recurse while | ||
* looking up fields of the class. At time of writing this occurs when checking if the component class | ||
* of a subfield is a leaf and is only a problem when the component class is the same as the parent class. | ||
*/ | ||
public class RecursiveTest { | ||
|
||
@Test | ||
public void referToBaseClass() { | ||
test(new ReferToBaseClass("hello"), new ReferToBaseClass(null)); | ||
} | ||
|
||
@Test | ||
public void referToSameClass() { | ||
test(new ReferToSameClass("test"), new ReferToSameClass(null)); | ||
} | ||
|
||
@Test | ||
public void marshallerReferToSameClass() { | ||
WireMarshaller<?> marshaller= WireMarshaller.WIRE_MARSHALLER_CL.get(ReferToSameClass.class); | ||
assertNotNull(marshaller); | ||
} | ||
|
||
@Test | ||
public void marshallerReferToBaseClass() { | ||
WireMarshaller<?> marshaller = WireMarshaller.WIRE_MARSHALLER_CL.get(ReferToBaseClass.class); | ||
assertNotNull(marshaller); | ||
} | ||
|
||
private void test(Base from, Base to) { | ||
from.copyTo(to); | ||
assertEquals(from.name(), to.name()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/test/java/net/openhft/chronicle/wire/recursive/ReferToBaseClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package net.openhft.chronicle.wire.recursive; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ReferToBaseClass extends ReferToSameClass { | ||
private final List<ReferToSameClass> list = new ArrayList<>(); | ||
|
||
public ReferToBaseClass(String name) { | ||
super(name); | ||
} | ||
|
||
public List<ReferToSameClass> list() { | ||
return list; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/test/java/net/openhft/chronicle/wire/recursive/ReferToSameClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package net.openhft.chronicle.wire.recursive; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ReferToSameClass extends Base { | ||
private final List<ReferToSameClass> list = new ArrayList<>(); | ||
|
||
public ReferToSameClass(String name) { | ||
super(name); | ||
} | ||
|
||
public List<ReferToSameClass> list() { | ||
return list; | ||
} | ||
} |