Skip to content

Commit

Permalink
Merge pull request quarkusio#14013 from matejvasek/fix_rec_qrdr
Browse files Browse the repository at this point in the history
Fix infinite recursion
  • Loading branch information
patriot1burke authored Jan 15, 2021
2 parents 39d99df + 65d8059 commit 93784be
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,14 @@ public Object create() {
continue;
Class paramType = m.getParameterTypes()[0];
Type paramGenericType = m.getGenericParameterTypes()[0];
Function<String, Object> extractor = mapper.extractor(paramType);
QueryPropertySetter propertySetter = null;
if (extractor == null) { // not string or primitive
propertySetter = mapper.setterFor(paramType, paramGenericType);
}
final Function<String, Object> extractor = mapper.extractor(paramType);

String name;
if (m.getName().length() > 4) {
name = Character.toLowerCase(m.getName().charAt(3)) + m.getName().substring(4);
} else {
name = m.getName().substring(3).toLowerCase();
}
final QueryPropertySetter finalPropertySetter = propertySetter;
ValueSetter setter = new ValueSetter() {
@Override
public void setValue(Object target, String propName, Object value) {
Expand All @@ -62,7 +57,11 @@ public Function<String, Object> getExtractor() {

@Override
public QueryPropertySetter getSetter() {
return finalPropertySetter;
if (extractor == null) {
return mapper.setterFor(paramType, paramGenericType);
} else {
return null;
}
}
};
properties.put(name, setter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ public void testNestedCollections() {

}

@Test
public void testRecursiveType() {
QueryObjectMapper mapper = new QueryObjectMapper();
QueryReader<RecursiveType> reader = mapper.readerFor(RecursiveType.class);
}

static Map.Entry<String, String> entry(String key, String value) {
return new Map.Entry() {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkus.funqy.test;

import java.util.List;

public class RecursiveType {
private int value;
private RecursiveType parent;
private List<RecursiveType> children;

public int getValue() {
return value;
}

public void setValue(int value) {
this.value = value;
}

public RecursiveType getParent() {
return parent;
}

public void setParent(RecursiveType parent) {
this.parent = parent;
}

public List<RecursiveType> getChildren() {
return children;
}

public void setChildren(List<RecursiveType> children) {
this.children = children;
}

}

0 comments on commit 93784be

Please sign in to comment.