Prefer getter types over field types

This commit is contained in:
Johannes Frohnmeyer 2022-11-01 20:40:53 +01:00
parent a69f1c07bd
commit 9f32d3b25d
Signed by: Johannes
GPG Key ID: E76429612C2929F4
3 changed files with 22 additions and 1 deletions

View File

@ -8,6 +8,9 @@ import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
/**
* Utility class for generating lists, to be used when data with an array root element
*/
public class GList {
public static <T> List<T> read(JsonReader reader, ThrowingFunction<JsonReader, T, IOException> read) throws IOException {
if (reader.isLenient() && reader.peek() != JsonToken.BEGIN_ARRAY) return List.of(read.apply(reader));

View File

@ -35,6 +35,16 @@ public class Main {
public EeE eEe;
public UnsupportedClass unsupported;
public String getUnsupported() {
return unsupported == null ? null : unsupported.text;
}
public void setUnsupported(String text) {
unsupported = new UnsupportedClass(text);
}
public void setJoe(String joe) {
}
@ -87,4 +97,12 @@ public class Main {
public enum EeE {
Yes, Yay, Aaee;
}
public static class UnsupportedClass {
private final String text;
public UnsupportedClass(String text) {
this.text = text;
}
}
}

View File

@ -163,9 +163,9 @@ public class Properties extends DelegateList<Property<?>> {
mergeSerializeNames(params, fields, getters, setters);
removeExtraFields();
names.addAll(params);
fields.stream().filter(f -> !containsName(names, f)).forEach(names::add);
getters.stream().filter(f -> !containsName(names, f)).forEach(names::add);
setters.stream().filter(f -> !containsName(names, f)).forEach(names::add);
fields.stream().filter(f -> !containsName(names, f)).forEach(names::add);
return new Properties(names, params, fields, getters, setters, constructorParams, builderParams);
}