Regarding the fastjson version error write javaBean error, fastjson version 1.2.62, fieldName: 8

1. Positioning problem

  1. Press f12 to view the request packet. If the status is 500, it indicates a server error.

  2. Check it in the compiler and fastjson reports an error.

  3. In servlet, fastjson is only used for serialization (java object to json string).

2. Analyze the problem

Introduction : JavaBeans should implement Serializablethe interface so that their state can be transmitted over the network or persisted to disk. Further proof is that the serialization went wrong.

write javaBean error, fastjson version 1.2.62, class com.itheima.pojo.Brand, fieldName : 8

Translation : JavaBean error, the fastjson version implemented by JavaBean is 1.2.62, Brand, field name: 8

3 commas, positioned layer by layer, and finally positioned at field 8. As we all know, the concept of fields usually appears in databases. When you open the database, you find that the field in row 8 is null. However, empty fields are not supported by default during serialization.

3. Solution

  1. Manually modify columns containing null values.

  2. When serializing, set: SerializerFeature.Ignore non-field acquisition (SerializerFeature.IgnoreNonFieldGetter)

 //加工为json 序列化
 String jsonString = JSON.toJSONString(brands, SerializerFeature.IgnoreNonFieldGetter);

Guess you like

Origin blog.csdn.net/m0_67574793/article/details/134641197