|
1 | 1 | package com.github.flexca.enot.core.serializer; |
2 | 2 |
|
| 3 | +import com.github.flexca.enot.core.EnotContext; |
3 | 4 | import com.github.flexca.enot.core.element.EnotElement; |
4 | 5 | import com.github.flexca.enot.core.element.value.CommonEnotValueType; |
5 | 6 | import com.github.flexca.enot.core.exception.EnotSerializationException; |
|
16 | 17 | public abstract class BaseElementSerializer implements ElementSerializer { |
17 | 18 |
|
18 | 19 | protected List<ElementSerializationResult> serializeBody(Object body, SerializationContext context, String jsonPath, |
19 | | - EnotRegistry enotRegistry, ConditionExpressionEvaluator conditionExpressionEvaluator) |
20 | | - throws EnotSerializationException { |
| 20 | + EnotContext enotContext) throws EnotSerializationException { |
21 | 21 |
|
22 | 22 | List<ElementSerializationResult> result = new ArrayList<>(); |
23 | 23 | if (body instanceof Collection<?> children) { |
24 | 24 | for (Object child : children) { |
25 | 25 | if (child instanceof EnotElement childElement) { |
26 | | - result.addAll(serializeBodyElement(childElement, context, jsonPath, enotRegistry, conditionExpressionEvaluator)); |
| 26 | + result.addAll(serializeBodyElement(childElement, context, jsonPath, enotContext)); |
27 | 27 | } else { |
28 | | - result.addAll(serializeBodyPrimitive(child, context, jsonPath, enotRegistry)); |
| 28 | + result.addAll(serializeBodyPrimitive(child, context, jsonPath, enotContext)); |
29 | 29 | } |
30 | 30 | } |
31 | 31 | } else if (body instanceof EnotElement child) { |
32 | | - result.addAll(serializeBodyElement(child, context, jsonPath, enotRegistry, conditionExpressionEvaluator)); |
| 32 | + result.addAll(serializeBodyElement(child, context, jsonPath, enotContext)); |
33 | 33 | } else { |
34 | | - result.addAll(serializeBodyPrimitive(body, context, jsonPath, enotRegistry)); |
| 34 | + result.addAll(serializeBodyPrimitive(body, context, jsonPath, enotContext)); |
35 | 35 | } |
36 | 36 | return result; |
37 | 37 | } |
38 | 38 |
|
39 | 39 | private List<ElementSerializationResult> serializeBodyElement(EnotElement element, SerializationContext context, String jsonPath, |
40 | | - EnotRegistry enotRegistry, ConditionExpressionEvaluator conditionExpressionEvaluator) |
41 | | - throws EnotSerializationException { |
| 40 | + EnotContext enotContext) throws EnotSerializationException { |
42 | 41 |
|
43 | | - EnotTypeSpecification typeSpecification = enotRegistry.getTypeSpecification(element.getType()).orElseThrow(() -> |
| 42 | + EnotTypeSpecification typeSpecification = enotContext.getEnotRegistry().getTypeSpecification(element.getType()).orElseThrow(() -> |
44 | 43 | new EnotSerializationException(EnotSerializer.COMMON_ERROR_MESSAGE, EnotJsonError.of(jsonPath, |
45 | 44 | "cannot find EnotTypeSpecification for element of type " + element.getType()))); |
46 | 45 |
|
47 | 46 | ElementSerializer elementSerializer = typeSpecification.getSerializer(element); |
48 | | - return elementSerializer.serialize(element, context, jsonPath, enotRegistry, conditionExpressionEvaluator); |
| 47 | + return elementSerializer.serialize(element, context, jsonPath, enotContext); |
49 | 48 | } |
50 | 49 |
|
51 | 50 | private List<ElementSerializationResult> serializeBodyPrimitive(Object body, SerializationContext context, String jsonPath, |
52 | | - EnotRegistry enotRegistry) throws EnotSerializationException { |
| 51 | + EnotContext enotContext) throws EnotSerializationException { |
53 | 52 |
|
54 | 53 | Object value; |
55 | 54 | Optional<String> placeholder = PlaceholderUtils.extractPlaceholder(body); |
|
0 commit comments