Skip to content

Commit 871652e

Browse files
committed
support NumberLayout for different type (double, integer,String) #42
1 parent 6fd15c2 commit 871652e

File tree

5 files changed

+67
-8
lines changed

5 files changed

+67
-8
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.asfjava.ui.core.schema;
2+
3+
import com.fasterxml.jackson.databind.BeanProperty;
4+
import com.fasterxml.jackson.module.jsonSchema.types.IntegerSchema;
5+
6+
class CustomIntegerSchema extends IntegerSchema {
7+
@Override
8+
public void enrichWithBeanProperty(BeanProperty beanProperty) {
9+
super.enrichWithBeanProperty(beanProperty);
10+
SchemaDecoratorUtil.get().decorate(beanProperty, this);
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
package io.asfjava.ui.core.schema;
22

33
import com.fasterxml.jackson.module.jsonSchema.factories.JsonSchemaFactory;
4+
import com.fasterxml.jackson.module.jsonSchema.types.IntegerSchema;
5+
import com.fasterxml.jackson.module.jsonSchema.types.NumberSchema;
46
import com.fasterxml.jackson.module.jsonSchema.types.StringSchema;
57

68
class CustomJsonSchemaFactory extends JsonSchemaFactory {
79
@Override
810
public StringSchema stringSchema() {
911
return new CustomStringSchema();
1012
}
13+
14+
@Override
15+
public NumberSchema numberSchema() {
16+
return new CustomNumberSchema();
17+
}
18+
19+
@Override
20+
public IntegerSchema integerSchema() {
21+
return new CustomIntegerSchema();
22+
}
1123
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.asfjava.ui.core.schema;
2+
3+
import com.fasterxml.jackson.databind.BeanProperty;
4+
import com.fasterxml.jackson.module.jsonSchema.types.NumberSchema;
5+
6+
class CustomNumberSchema extends NumberSchema {
7+
@Override
8+
public void enrichWithBeanProperty(BeanProperty beanProperty) {
9+
super.enrichWithBeanProperty(beanProperty);
10+
SchemaDecoratorUtil.get().decorate(beanProperty, this);
11+
}
12+
}
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
package io.asfjava.ui.core.schema;
22

3-
import java.lang.annotation.Annotation;
4-
53
import com.fasterxml.jackson.databind.BeanProperty;
64
import com.fasterxml.jackson.module.jsonSchema.types.StringSchema;
75

8-
import io.asfjava.ui.core.SchemaDecoratorFactory;
9-
106
class CustomStringSchema extends StringSchema {
117

128
@Override
139
public void enrichWithBeanProperty(BeanProperty beanProperty) {
1410
super.enrichWithBeanProperty(beanProperty);
15-
Iterable<Annotation> it = beanProperty.getMember().annotations();
16-
it.forEach(
17-
annotation -> SchemaDecoratorFactory.getInstance().getDecorator(annotation.annotationType().getName())
18-
.ifPresent(decorator -> decorator.customizeSchema(beanProperty, this)));
11+
SchemaDecoratorUtil.get().decorate(beanProperty, this);
1912
}
2013

2114
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.asfjava.ui.core.schema;
2+
3+
import java.lang.annotation.Annotation;
4+
5+
import com.fasterxml.jackson.databind.BeanProperty;
6+
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
7+
8+
import io.asfjava.ui.core.SchemaDecoratorFactory;
9+
10+
final class SchemaDecoratorUtil {
11+
12+
void decorate(BeanProperty beanProperty, JsonSchema simpleTypeSchema) {
13+
Iterable<Annotation> it = beanProperty.getMember().annotations();
14+
it.forEach(
15+
annotation -> SchemaDecoratorFactory.getInstance().getDecorator(annotation.annotationType().getName())
16+
.ifPresent(decorator -> decorator.customizeSchema(beanProperty, simpleTypeSchema)));
17+
}
18+
19+
static SchemaDecoratorUtil get() {
20+
if (instance == null) {
21+
instance = new SchemaDecoratorUtil();
22+
}
23+
return instance;
24+
}
25+
26+
private static SchemaDecoratorUtil instance;
27+
28+
private SchemaDecoratorUtil() {
29+
}
30+
}

0 commit comments

Comments
 (0)