简体   繁体   English

Jersey 1.x正在将我的序列化null字段解释为值为“ null”的字符串。 我该如何预防?

[英]Jersey 1.x is interpreting my serialized null fields as Strings with the value of “null”. How do I prevent this?

This is a very nasty bug. 这是一个非常讨厌的错误。 Here's what's happening: When I run client to server tests, my tests all work. 这是发生的事情:当我运行客户端到服务器测试时,我的测试全部正常。 When I query a linux server with the same source code, it fails. 当我使用相同的源代码查询Linux服务器时,它失败。

It only occurs on linux (perhaps macs, I haven't checked). 它仅在linux上发生(也许是macs,我没有检查过)。 I'm on Windows 7 and can't reproduce this. 我使用的是Windows 7,无法重现。 But, this may be an red herring . 但是, 这可能是个红鲱鱼 Another difference is that I'm running off of an exploded ear and the failing servers are running off of a packaged ear. 另一个区别是,我快要爆了,而发生故障的服务器也快要打包了。 If this is the culprit, it probably is a classpath issue. 如果这是罪魁祸首,则可能是类路径问题。

This has to do with the server. 这与服务器有关。 If I change my client code to call a linux server, it will fail. 如果我改变我的客户端代码来调用一台Linux服务器,它就会失败。 To me that rules out the client's responsibility. 对我而言,这排除了客户的责任。

I've set a break point on the servers to compare the input and to my surprise the content of the entity looks very different. 我在服务器上设置了一个断点来比较输入,令我惊讶的是,实体的内容看起来非常不同。 My working server makes the object look like this: 我的工作服务器使对象看起来像这样:

在此处输入图片说明

When I set the breakpoint on the linux server, it looks like this: 当我在linux服务器上设置断点时,它看起来像这样:

在此处输入图片说明

Notice how the second one is full of strings with the value of "null" and empty objects. 注意第二个如何充满值为“ null”和空对象的字符串。 What could be causing this? 是什么原因造成的? I'm using Jersey 1.x and Jackson 2.0 and JAXB. 我正在使用Jersey 1.x和Jackson 2.0和JAXB。 But this is a huge project that may have older versions of those jars in the classpath. 但这是一个巨大的项目,可能在类路径中有这些jar的较旧版本。 I'm not even sure where to suspect this error could be coming from. 我什至不知道该错误可能来自何处。

I've discovered the cause of this was in fact a classpath issue. 我发现造成这种情况的原因实际上是类路径问题。 I was using a different install of glassfish compared to everyone else. 与其他所有人相比,我使用的玻璃鱼的安装方式不同。 Everyone else's glassfish had extra libs under "glassfish/lib": 每个人的玻璃鱼在“ glassfish / lib”下都有额外的lib:

jackson-asl-0.9.4.jar
jersey-bundle-1.0.3.1.jar
jsr311-api-1.0.jar

Once I removed these 3 libs, my code worked consistently everywhere. 一旦删除了这3个库,我的代码就可以在所有地方一致地工作了。 I removed all 3 at once, so I'm not sure if they are all necessary to remove. 我一次删除了所有3个,因此我不确定是否都需要删除它们。 But at least one of these jars was responsible. 但是这些罐子中至少有一个是负责任的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jersey 1.x正在用空格符号替换加号。我怎么能阻止这个? - Jersey 1.x is replacing the plus symbol with a space symbol. How can I prevent this? 如何防止 Map 中的空值和 bean 中的空字段通过 Jackson 序列化 - How to prevent null values inside a Map and null fields inside a bean from getting serialized through Jackson 如何在Jersey中从我的JSON请求中排除空字段? - How can I exclude null fields form my JSON request in Jersey? 使用 Jackson 1.x 时如何解决空指针错误 - How to solve NULL pointer error when using Jackson 1.x 如何从JtextField中捕获空值? - How do I catch the null value from my JtextField? 为什么不将此空值序列化? - why is this null value not being serialized? 如何处理查询中没有值且数据类型为整数的字段返回的空值 - How do I handle null value returned by a query for fields with no value in them and datatype as integer Android表单验证-如何防止在按下按钮时空字段使我的应用程序崩溃? - Android Form Validation - How do I prevent a null field from crashing my application on button press? 如何在Jersey JAX-RS实现中编组空字段? - How to marshall null fields in Jersey JAX-RS implementation? 泽西岛1.x和Tomcat:如何以编程方式注册ContainerRequestFilter,即没有web.xml? - Jersey 1.x and Tomcat: how to register a ContainerRequestFilter programmatically, i.e. without web.xml?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM