分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

jackjson-databind-2.9.3 笔记

发布时间:2023-09-06 01:55责任编辑:蔡小小关键词:jsjson

问题

客户端请求:

{"skip":0,"take":10,"corpName":"","cityCode":{}}

服务器端接收参数

 ???????????@RequestBody query: ListQueryModel, ???????????corpName: String

调试

jackson-databind-2.9.3.jar!/com/fasterxml/jackson/databind/deser/BeanDeserializer.class

private final Object vanillaDeserialize(JsonParser p, DeserializationContext ctxt, JsonToken t) throws IOException { ???????Object bean = this._valueInstantiator.createUsingDefault(ctxt); ???????p.setCurrentValue(bean); ???????if (p.hasTokenId(5)) { ???????????String propName = p.getCurrentName(); ???????????do { ???????????????p.nextToken(); ???????????????SettableBeanProperty prop = this._beanProperties.find(propName); ???????????????if (prop != null) { ???????????????????try { ???????????????????????prop.deserializeAndSet(p, ctxt, bean); ???????????????????} catch (Exception var8) { ???????????????????????this.wrapAndThrow(var8, bean, propName, ctxt); ???????????????????} ???????????????} else { ???????????????????this.handleUnknownVanilla(p, ctxt, bean, propName); ???????????????} ???????????} while((propName = p.nextFieldName()) != null); ???????} ???????return bean; ???}

对比之前的版本:
jackson-databind-2.8.10-sources.jar!/com/fasterxml/jackson/databind/deser/BeanDeserializer.java

private final Object vanillaDeserialize(JsonParser p, ???????????DeserializationContext ctxt, JsonToken t) ???????throws IOException ???{ ???????final Object bean = _valueInstantiator.createUsingDefault(ctxt); ???????// [databind#631]: Assign current value, to be accessible by custom serializers ???????p.setCurrentValue(bean); ???????if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) { ???????????String propName = p.getCurrentName(); ???????????do { ???????????????p.nextToken(); ???????????????SettableBeanProperty prop = _beanProperties.find(propName); ???????????????if (prop != null) { // normal case ???????????????????try { ???????????????????????prop.deserializeAndSet(p, ctxt, bean); ???????????????????} catch (Exception e) { ???????????????????????wrapAndThrow(e, bean, propName, ctxt); ???????????????????} ???????????????????continue; ???????????????} ???????????????handleUnknownVanilla(p, ctxt, bean, propName); ???????????} while ((propName = p.nextFieldName()) != null); ???????} ???????return bean; ???} ???protected void handleUnknownVanilla(JsonParser p, DeserializationContext ctxt, Object bean, String propName) ???????throws IOException ???{ ???????if (_ignorableProps != null && _ignorableProps.contains(propName)) { ???????????handleIgnoredProperty(p, ctxt, bean, propName); ???????} else if (_anySetter != null) { ???????????try { ??????????????// should we consider return type of any setter? ???????????????_anySetter.deserializeAndSet(p, ctxt, bean, propName); ???????????} catch (Exception e) { ???????????????wrapAndThrow(e, bean, propName, ctxt); ???????????} ???????} else { ???????????// Unknown: let's call handler method ???????????handleUnknownProperty(p, ctxt, bean, propName); ????????????????} ???} ???protected void handleUnknownProperty(JsonParser p, DeserializationContext ctxt, ???????????Object beanOrClass, String propName) ???????throws IOException ???{ ???????if (_ignoreAllUnknown) { ???????????p.skipChildren(); ???????????return; ???????} ???????if (_ignorableProps != null && _ignorableProps.contains(propName)) { ???????????handleIgnoredProperty(p, ctxt, beanOrClass, propName); ???????} ???????// Otherwise use default handling (call handler(s); if not ???????// handled, throw exception or skip depending on settings) ???????super.handleUnknownProperty(p, ctxt, beanOrClass, propName); ???}

jackson-databind-2.8.10-sources.jar!/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java

 ???protected void handleUnknownProperty(JsonParser p, DeserializationContext ctxt, Object instanceOrClass, String propName) ???????throws IOException ???{ ???????if (instanceOrClass == null) { ???????????instanceOrClass = handledType(); ???????} ???????// Maybe we have configured handler(s) to take care of it? ???????if (ctxt.handleUnknownProperty(p, this, instanceOrClass, propName)) { ???????????return; ???????} ???????/* But if we do get this far, need to skip whatever value we ????????* are pointing to now (although handler is likely to have done that already) ????????*/ ???????p.skipChildren(); ???}

对比发现

2.8.10 会忽略掉客户端请求中多余的属性。
2.9.3 会报错。

这就是坑。

jackjson-databind-2.9.3 笔记

原文地址:https://www.cnblogs.com/newsea/p/9062705.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved