|
| 1 | +/* |
| 2 | + * Copyright 2002-2022 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.graphql.data.jackson; |
| 18 | + |
| 19 | +import com.fasterxml.jackson.databind.BeanProperty; |
| 20 | +import com.fasterxml.jackson.databind.JsonSerializer; |
| 21 | +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; |
| 22 | +import com.fasterxml.jackson.databind.ser.std.ReferenceTypeSerializer; |
| 23 | +import com.fasterxml.jackson.databind.type.ReferenceType; |
| 24 | +import com.fasterxml.jackson.databind.util.NameTransformer; |
| 25 | +import org.springframework.graphql.data.ArgumentValue; |
| 26 | + |
| 27 | +import java.io.Serial; |
| 28 | + |
| 29 | +public class ArgumentValueSerializer extends ReferenceTypeSerializer<ArgumentValue<?>> { |
| 30 | + |
| 31 | + @Serial |
| 32 | + private static final long serialVersionUID = 1L; |
| 33 | + |
| 34 | + public ArgumentValueSerializer(final ReferenceType fullType, final boolean staticTyping, |
| 35 | + final TypeSerializer vts, final JsonSerializer<Object> ser) { |
| 36 | + |
| 37 | + super(fullType, staticTyping, vts, ser); |
| 38 | + } |
| 39 | + |
| 40 | + protected ArgumentValueSerializer(final ArgumentValueSerializer base, final BeanProperty property, |
| 41 | + final TypeSerializer vts, final JsonSerializer<?> valueSer, |
| 42 | + final NameTransformer unwrapper, final Object suppressableValue, |
| 43 | + final boolean suppressNulls) { |
| 44 | + |
| 45 | + super(base, property, vts, valueSer, unwrapper, suppressableValue, suppressNulls); |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + protected ReferenceTypeSerializer<ArgumentValue<?>> withResolved(final BeanProperty prop, final TypeSerializer vts, |
| 50 | + final JsonSerializer<?> valueSer, final NameTransformer unwrapper) { |
| 51 | + |
| 52 | + return new ArgumentValueSerializer(this, prop, vts, valueSer, unwrapper, _suppressableValue, _suppressNulls); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public ReferenceTypeSerializer<ArgumentValue<?>> withContentInclusion(final Object suppressableValue, final boolean suppressNulls) { |
| 57 | + return new ArgumentValueSerializer(this, _property, _valueTypeSerializer, |
| 58 | + _valueSerializer, _unwrapper, suppressableValue, suppressNulls); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + protected boolean _isValuePresent(final ArgumentValue<?> value) { |
| 63 | + return !value.isOmitted(); |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + protected Object _getReferenced(final ArgumentValue<?> value) { |
| 68 | + return value.value(); |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + protected Object _getReferencedIfPresent(final ArgumentValue<?> value) { |
| 73 | + return value.value(); |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | +} |
0 commit comments