Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] 兼容jackson的序列化/反序列化注解 #2217

Closed
wwulfric opened this issue Jan 26, 2024 · 1 comment
Closed

[FEATURE] 兼容jackson的序列化/反序列化注解 #2217

wwulfric opened this issue Jan 26, 2024 · 1 comment
Labels
enhancement New feature or request fixed
Milestone

Comments

@wwulfric
Copy link

请描述您的需求或者改进建议

对您想要需求或建议的清晰简洁的描述。

#1985 里提到了,希望能够兼容JsonDeserialize注解

请描述你建议的实现方案

对您想要需求或建议的实现方案的详细描述。

解析prom经典场景,prom返回的是values: [[]] 格式,表示多个指标点,里面的[] 是[timestamp, value],希望能解析为对象而不是数组。
image

目前实现的方式是:

public class PrometheusQueryRangeValueDeserializer extends JsonDeserializer<PrometheusQueryRangeValue> implements ObjectReader<PrometheusQueryRangeValue> {
    @Override
    public PrometheusQueryRangeValue deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException {
        JsonNode node = jsonParser.getCodec().readTree(jsonParser);
        ...
    }

    @Override
    public PrometheusQueryRangeValue readObject(JSONReader jsonReader, Type fieldType, Object fieldName, long features) {
        JSONArray array = jsonReader.readJSONArray();
        ...
    }

这样一方面继承jackson 的JsonDeserializer,一方面实现fastjson2的ObjectReader,然后加上2个注解

@JsonDeserialize(contentUsing = PrometheusQueryRangeValueDeserializer.class)
@JSONType(deserializer = PrometheusQueryRangeValueDeserializer.class)

我理解这2个注解应该可以融合。fastjson发现有JsonDeserialize的时候,尝试用contentUsing对应的类的readObject方法?

描述您考虑过的替代方案

对您考虑过的任何替代解决方案或功能的描述。

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

@wwulfric wwulfric added the enhancement New feature or request label Jan 26, 2024
@wenshao wenshao added this to the 2.0.46 milestone Jan 26, 2024
@wenshao wenshao added the fixed label Jan 27, 2024
@wenshao
Copy link
Member

wenshao commented Jan 29, 2024

https://github.com/alibaba/fastjson2/releases/tag/2.0.46
问题已修复,请用新版本

@wenshao wenshao closed this as completed Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed
Projects
None yet
Development

No branches or pull requests

2 participants