Skip to content
This repository was archived by the owner on Oct 26, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.wuespace.telestion.api.message.optionalprops.opt1;

import com.fasterxml.jackson.annotation.JsonProperty;

public record Opt1Example(
@JsonProperty @OptionalJsonProperty(defaultString = "foo") String foo,
// We can even give global default parameters by inferring them into @OptionalJsonProperty
@JsonProperty @OptionalJsonProperty int bar,
@JsonProperty
boolean extraBar, // Not everything must be optional
@JsonProperty @OptionalJsonProperty(defaultChar = 'F')
char extraFoo) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.wuespace.telestion.api.message.optionalprops.opt1;

public @interface OptionalJsonProperty {
byte defaultByte() default -1;
short defaultShort() default -1;
int defaultInt() default -1;
long defaultLong() default -1;
float defaultFloat() default -1.0f;
double defaultDouble() default -1.0;
char defaultChar() default 0x0;
boolean defaultBool() default false;
String defaultString() default "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.wuespace.telestion.api.message.optionalprops.opt2;

import com.fasterxml.jackson.annotation.JsonProperty;

public record Opt2Example(@JsonProperty @OptionalString(defaultString = "foo") String s,
@JsonProperty @OptionalBool(defaultBool = false) boolean bool,
@JsonProperty @OptionalByte(defaultByte = 127) byte b,
@JsonProperty @OptionalInt(defaultInt = -1) int i) {
/*
* Note that this implementation could also be improved by adding global default parameters to each of the
* annotations as it was shown by example 1.
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.wuespace.telestion.api.message.optionalprops.opt2;

public @interface OptionalBool {
boolean defaultBool();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.wuespace.telestion.api.message.optionalprops.opt2;

public @interface OptionalByte {
byte defaultByte();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.wuespace.telestion.api.message.optionalprops.opt2;

public @interface OptionalInt {
int defaultInt();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.wuespace.telestion.api.message.optionalprops.opt2;

public @interface OptionalString {
String defaultString();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.wuespace.telestion.api.message.optionalprops.opt2;

public @interface z_andSoOn {
String andAnAnnotationForEveryOtherNotMentionedDatatype();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.wuespace.telestion.api.message.optionalprops.opt3;

import com.fasterxml.jackson.annotation.JsonProperty;

public record Opt3Example(@JsonProperty @OptionalBool(defaultBool = true) boolean bool,
@JsonProperty @OptionalFloatingPoint(defaultFloat = 0.0) float f,
@JsonProperty @OptionalFloatingPoint(defaultFloat = 0.1) double d,
@JsonProperty @OptionalInteger(defaultInteger = 10) long l,
@JsonProperty @OptionalInteger(defaultInteger = -1204) int i,
@JsonProperty @OptionalString(defaultString = "cb0s Was Here :D") String s,
// It might be beneficial to add one more annotation for chars
@JsonProperty @OptionalInteger(defaultInteger = 65) char c) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.wuespace.telestion.api.message.optionalprops.opt3;

public @interface OptionalBool {
boolean defaultBool();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.wuespace.telestion.api.message.optionalprops.opt3;

public @interface OptionalFloatingPoint {
double defaultFloat();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.wuespace.telestion.api.message.optionalprops.opt3;

public @interface OptionalInteger {
long defaultInteger();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.wuespace.telestion.api.message.optionalprops.opt3;

public @interface OptionalString {
String defaultString();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package de.wuespace.telestion.api.message.optionalprops.opt4;

import com.fasterxml.jackson.annotation.JsonProperty;

public record Opt4Example(@JsonProperty @OptionalJsonProperty(defaultVal = "34.1") float f,
@JsonProperty @OptionalJsonProperty(defaultVal = "123") int i,
@JsonProperty @OptionalJsonProperty(defaultVal = "This is a proper String") String s) {
/*
* With this solution, the config loader would automatically parse those values to the designated data types.
* This works around the problem imposed by the static type system by java, but could be notably slower.
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.wuespace.telestion.api.message.optionalprops.opt4;

public @interface OptionalJsonProperty {
String defaultVal();
}