-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-846 - Fix determination of target graph property type.
* Fix determination of target graph property type. The algorithm that determines the graph property type is faulty: It is not enough to retrieve the declared methods of a class and filter out the synthetic ones to get the most specific method implementation or overwrite. The main goal of that code in FieldInfo is about getting the actual return type without trying to figure this out from generic parameters. This is done now in multiple steps: If we find more than one but one none synthetic, we use this (same as before). If all we finde are synthetic, we keep those declared on the actual converter class. If those are more than one, we take the one not returning generic Object. This fixes #845.
- Loading branch information
1 parent
c689b34
commit d3fe765
Showing
10 changed files
with
501 additions
and
74 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
78 changes: 78 additions & 0 deletions
78
...n-tests/src/test/java/org/neo4j/ogm/domain/convertible/numbers/AbstractListConverter.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,78 @@ | ||
/* | ||
* Copyright (c) 2002-2020 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.neo4j.ogm.domain.convertible.numbers; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
import org.neo4j.ogm.typeconversion.AttributeConverter; | ||
|
||
/** | ||
* An abstract base class for converters converting list of things to a string. | ||
* | ||
* @param <T> The type of one thing | ||
* @author Michael J. Simons | ||
*/ | ||
abstract class AbstractListConverter<T> implements AttributeConverter<List<T>, String> { | ||
|
||
private final Function<T, String> writeFunction; | ||
private final Function<String, T> readFunction; | ||
|
||
AbstractListConverter(Function<T, String> writeFunction, | ||
Function<String, T> readFunction) { | ||
this.writeFunction = writeFunction; | ||
this.readFunction = readFunction; | ||
} | ||
|
||
@Override | ||
public String toGraphProperty(List<T> value) { | ||
return value == null ? null : value.stream().map(writeFunction).collect(Collectors.joining(",")); | ||
} | ||
|
||
@Override public List<T> toEntityAttribute(String value) { | ||
return value == null ? null : Arrays.stream(value.split(",")).map(readFunction).collect(Collectors.toList()); | ||
} | ||
|
||
protected static abstract class AbstractIntegerListConverter extends AbstractListConverter<Integer> { | ||
|
||
AbstractIntegerListConverter(int radix) { | ||
super( | ||
i -> Integer.toString(i, radix), | ||
s -> Integer.valueOf(s, radix) | ||
); | ||
} | ||
} | ||
|
||
public static class Base36NumberConverter extends AbstractIntegerListConverter { | ||
|
||
public Base36NumberConverter() { | ||
super(36); | ||
} | ||
} | ||
|
||
public static class FoobarListConverter extends AbstractListConverter<Foobar> { | ||
|
||
public FoobarListConverter() { | ||
super(Foobar::getValue, Foobar::new); | ||
} | ||
} | ||
} | ||
|
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
38 changes: 38 additions & 0 deletions
38
...-ogm-integration-tests/src/test/java/org/neo4j/ogm/domain/convertible/numbers/Foobar.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,38 @@ | ||
/* | ||
* Copyright (c) 2002-2020 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.neo4j.ogm.domain.convertible.numbers; | ||
|
||
/** | ||
* An arbitrary object that is not an entity and collections of it should not be treated as | ||
* assocations as they are annoated with {@link org.neo4j.ogm.annotation.typeconversion.Convert @Convert}. | ||
* | ||
* @author Michael J. Simons | ||
*/ | ||
public final class Foobar { | ||
|
||
private final String value; | ||
|
||
public Foobar(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...gration-tests/src/test/java/org/neo4j/ogm/domain/convertible/numbers/FoobarConverter.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,37 @@ | ||
/* | ||
* Copyright (c) 2002-2020 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.neo4j.ogm.domain.convertible.numbers; | ||
|
||
import org.neo4j.ogm.typeconversion.AttributeConverter; | ||
|
||
/** | ||
* @author Michael J. Simons | ||
*/ | ||
public class FoobarConverter implements AttributeConverter<Foobar, String> { | ||
|
||
@Override | ||
public String toGraphProperty(Foobar value) { | ||
return value == null ? null : value.getValue(); | ||
} | ||
|
||
@Override | ||
public Foobar toEntityAttribute(String value) { | ||
return value == null ? null : new Foobar(value); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ion-tests/src/test/java/org/neo4j/ogm/domain/convertible/numbers/FoobarListConverter.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,32 @@ | ||
/* | ||
* Copyright (c) 2002-2020 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.neo4j.ogm.domain.convertible.numbers; | ||
|
||
/** | ||
* The way methods are synthesized is different with public inner classes | ||
* (compare to {@link org.neo4j.ogm.domain.convertible.numbers.AbstractListConverter.FoobarListConverter}). | ||
* | ||
* @author Michael J. Simons | ||
*/ | ||
public class FoobarListConverter extends AbstractListConverter<Foobar> { | ||
|
||
public FoobarListConverter() { | ||
super(Foobar::getValue, Foobar::new); | ||
} | ||
} |
Oops, something went wrong.