2 Star 1 Fork 2

Nottyjay / dubbox

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
jackson.html 8.44 KB
一键复制 编辑 原始数据 按行查看 历史
Li Shen 提交于 2014-12-08 17:15 . update docs
<!DOCTYPE html><html><head><title>jackson</title><meta http-equiv=Content-Type content="text/html; charset=utf-8"><style type=text/css>html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0}body{font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:14px;line-height:1.6;color:#333;background-color:#fff;padding:20px;max-width:960px;margin:0 auto}body>:first-child{margin-top:0!important}body>:last-child{margin-bottom:0!important}p,blockquote,ul,ol,dl,table,pre{margin:15px 0}h1,h2,h3,h4,h5,h6{margin:20px 0 10px;padding:0;font-weight:700;-webkit-font-smoothing:antialiased}h1 tt,h1 code,h2 tt,h2 code,h3 tt,h3 code,h4 tt,h4 code,h5 tt,h5 code,h6 tt,h6 code{font-size:inherit}h1{font-size:28px;color:#000}h2{font-size:24px;border-bottom:1px solid #ccc;color:#000}h3{font-size:18px}h4{font-size:16px}h5{font-size:14px}h6{color:#777;font-size:14px}body>h2:first-child,body>h1:first-child,body>h1:first-child+h2,body>h3:first-child,body>h4:first-child,body>h5:first-child,body>h6:first-child{margin-top:0;padding-top:0}a:first-child h1,a:first-child h2,a:first-child h3,a:first-child h4,a:first-child h5,a:first-child h6{margin-top:0;padding-top:0}h1+p,h2+p,h3+p,h4+p,h5+p,h6+p{margin-top:10px}a{color:#4183C4;text-decoration:none}a:hover{text-decoration:underline}ul,ol{padding-left:30px}ul li>:first-child,ol li>:first-child,ul li ul:first-of-type,ol li ol:first-of-type,ul li ol:first-of-type,ol li ul:first-of-type{margin-top:0}ul ul,ul ol,ol ol,ol ul{margin-bottom:0}dl{padding:0}dl dt{font-size:14px;font-weight:700;font-style:italic;padding:0;margin:15px 0 5px}dl dt:first-child{padding:0}dl dt>:first-child{margin-top:0}dl dt>:last-child{margin-bottom:0}dl dd{margin:0 0 15px;padding:0 15px}dl dd>:first-child{margin-top:0}dl dd>:last-child{margin-bottom:0}pre,code,tt{font-size:12px;font-family:Consolas,"Liberation Mono",Courier,monospace}code,tt{margin:0 0;padding:0 0;white-space:nowrap;border:1px solid #eaeaea;background-color:#f8f8f8;border-radius:3px}pre>code{margin:0;padding:0;white-space:pre;border:none;background:0 0}pre{background-color:#f8f8f8;border:1px solid #ccc;font-size:13px;line-height:19px;overflow:auto;padding:6px 10px;border-radius:3px}pre code,pre tt{background-color:transparent;border:none}kbd{-moz-border-bottom-colors:none;-moz-border-left-colors:none;-moz-border-right-colors:none;-moz-border-top-colors:none;background-color:#DDD;background-image:linear-gradient(#F1F1F1,#DDD);background-repeat:repeat-x;border-color:#DDD #CCC #CCC #DDD;border-image:none;border-radius:2px 2px 2px 2px;border-style:solid;border-width:1px;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;line-height:10px;padding:1px 4px}blockquote{border-left:4px solid #DDD;padding:0 15px;color:#777}blockquote>:first-child{margin-top:0}blockquote>:last-child{margin-bottom:0}hr{clear:both;margin:15px 0;height:0;overflow:hidden;border:none;background:0 0;border-bottom:4px solid #ddd;padding:0}table th{font-weight:700}table th,table td{border:1px solid #ccc;padding:6px 13px}table tr{border-top:1px solid #ccc;background-color:#fff}table tr:nth-child(2n){background-color:#f8f8f8}img{max-width:100%}</style><style type=text/css>.highlight{background:#fff}.highlight .c{color:#998;font-style:italic}.highlight .err{color:#a61717;background-color:#e3d2d2}.highlight .k{font-weight:700}.highlight .o{font-weight:700}.highlight .cm{color:#998;font-style:italic}.highlight .cp{color:#999;font-weight:700}.highlight .c1{color:#998;font-style:italic}.highlight .cs{color:#999;font-weight:700;font-style:italic}.highlight .gd{color:#000;background-color:#fdd}.highlight .gd .x{color:#000;background-color:#faa}.highlight .ge{font-style:italic}.highlight .gr{color:#a00}.highlight .gh{color:#999}.highlight .gi{color:#000;background-color:#dfd}.highlight .gi .x{color:#000;background-color:#afa}.highlight .go{color:#888}.highlight .gp{color:#555}.highlight .gs{font-weight:700}.highlight .gu{color:#aaa}.highlight .gt{color:#a00}.highlight .kc{font-weight:700}.highlight .kd{font-weight:700}.highlight .kp{font-weight:700}.highlight .kr{font-weight:700}.highlight .kt{color:#458;font-weight:700}.highlight .m{color:#099}.highlight .s{color:#d14}.highlight .na{color:teal}.highlight .nb{color:#0086B3}.highlight .nc{color:#458;font-weight:700}.highlight .no{color:teal}.highlight .ni{color:purple}.highlight .ne{color:#900;font-weight:700}.highlight .nf{color:#900;font-weight:700}.highlight .nn{color:#555}.highlight .nt{color:navy}.highlight .nv{color:teal}.highlight .ow{font-weight:700}.highlight .w{color:#bbb}.highlight .mf{color:#099}.highlight .mh{color:#099}.highlight .mi{color:#099}.highlight .mo{color:#099}.highlight .sb{color:#d14}.highlight .sc{color:#d14}.highlight .sd{color:#d14}.highlight .s2{color:#d14}.highlight .se{color:#d14}.highlight .sh{color:#d14}.highlight .si{color:#d14}.highlight .sx{color:#d14}.highlight .sr{color:#009926}.highlight .s1{color:#d14}.highlight .ss{color:#990073}.highlight .bp{color:#999}.highlight .vc{color:teal}.highlight .vg{color:teal}.highlight .vi{color:teal}.highlight .il{color:#099}.task-list{padding-left:10px;margin-bottom:0}.task-list li{margin-left:20px}.task-list-item{list-style-type:none;padding-left:10px}.task-list-item label{font-weight:400}.task-list-item.enabled label{cursor:pointer}.task-list-item+.task-list-item{margin-top:3px}.task-list-item-checkbox{display:inline-block;margin-left:-20px;margin-right:3px;vertical-align:1px}</style><body><h1>Dubbo Jackson序列化使用说明</h1><p><strong>作者:Dylan</strong></p><p><strong>文档版权:<a href=https://creativecommons.org/licenses/by-nd/3.0/deed.zh>Creative Commons 3.0许可证 署名-禁止演绎</a></strong></p><p>Jackson序列化提供了对基本数据类型和简单Bean的序列化的支持, 以及对类继承的支持。</p><p>已经经过测试的数据类型包括:</p><pre><code>Boolean/boolean
Long/long
Integer/int
Double/double
Short/short
Float/float
Byte/byte
java.util.Date
org.joda.time.DateTime
</code></pre><p>以及由这些基本数据类型组成的数组和Bean, 如 int[], String[]等.</p><h3>jackson序列化使用</h3><div class="highlight highlight-xml"><pre>&lt;<span class=pl-ent>dubbo</span><span class=pl-ent>:</span><span class=pl-ent>protocol</span> <span class=pl-e>name</span>=<span class=pl-s1><span class=pl-pds>"</span>dubbo<span class=pl-pds>"</span></span> <span class=pl-e>port</span>=<span class=pl-s1><span class=pl-pds>"</span>20880<span class=pl-pds>"</span></span> <span class=pl-e>serialization</span>=<span class=pl-s1><span class=pl-pds>"</span>jackson<span class=pl-pds>"</span></span> /&gt;</pre></div><h3>自定义ObjectMapper</h3><p>默认情况下,Jackson序列化和反序列化时所使用的ObjectMapper定义如下:</p><div class="highlight highlight-java"><pre> @<span class=pl-stj>Override</span>
<span class=pl-s>public</span> <span class=pl-stj>ObjectMapper</span> getObjectMapper() {
<span class=pl-stj>ObjectMapper</span> objectMapper <span class=pl-k>=</span> <span class=pl-k>new</span> <span class=pl-stj>ObjectMapper</span>();
objectMapper<span class=pl-k>.</span>disable(<span class=pl-stj>SerializationFeature</span><span class=pl-c1><span class=pl-k>.</span>FAIL_ON_EMPTY_BEANS</span>);
<span class=pl-c>// objectMapper.disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE);</span>
objectMapper<span class=pl-k>.</span>disable(<span class=pl-stj>DeserializationFeature</span><span class=pl-c1><span class=pl-k>.</span>FAIL_ON_UNKNOWN_PROPERTIES</span>);
objectMapper<span class=pl-k>.</span>setTimeZone(<span class=pl-stj>TimeZone</span><span class=pl-k>.</span>getDefault());
<span class=pl-k>return</span> objectMapper;
}</pre></div><p>如果需要自定义JacksonObjectMapperProvider, 开发者可以通过实现com.alibaba.dubbo.common.json.JacksonObjectMapperProvider接口进行自定义,并在/META-INF/dubbo/中添加文件 com.alibaba.dubbo.common.json.JacksonObjectMapperProvider,内容示例如下:</p><pre><code>jackson=com.alibaba.dubbo.examples.jackson.jacksonprovider.CustomJacksonObjectMapperProvider
</code></pre><h3>已知问题</h3><ol class=task-list><li>不支持泛型对象的序列化, 如 List,Map类型的序列化和反序列化</li></ol>
Java
1
https://gitee.com/nottyjay/dubbox.git
git@gitee.com:nottyjay/dubbox.git
nottyjay
dubbox
dubbox
master

搜索帮助