The solution to the problem that Hessian cannot transmit BigDecimal correctly when RPC interface is called

  When using the company's self-developed RPC framework (the framework is serialized based on the hessian protocol) for the project, the transmission data defined by the RPC interface contains BigDecimal type data. After testing, it is found that the transmission parameter 158.00 is transmitted, but the value obtained is 0.00. , Cannot be transmitted correctly. The hessian dependency version referenced by the project is as follows.

		<dependency>
			<groupId>com.caucho</groupId>
			<artifactId>hessian</artifactId>
			<version>4.0.7</version>
		</dependency>

  The reason for this phenomenon : the 4.0.7 version of the hessian package does not specify the serialization and deserialization methods of BigDecimal, which makes BigDecimal use the default serialization method during transmission, which causes the above problems.

  There are multiple solutions :

  1. Upgrade the hessian package version to a suitable version, such as 4.0.52 or 4.0.37 or other versions that specify the serialization and deserialization methods for BigDecimal.
  2. Add the following two files to the original package and type into the hessian package.
  • /META-INF/hessian/serializers,内容如下:
    java.math.BigDecimal=com.caucho.hessian.io.StringValueSerializer
  • /META-INF/hessian/deserializers,内容如下:
    java.math.BigDecimal=com.caucho.hessian.io.BigDecimalDeserializer

  This article uses the first method to solve, upgrade hessian to 4.0.52.

  The 4.0.7 version of the hessian package structure is as follows: The
4.0.7 version of the hessian package
  4.0.52 version of the hessian package structure is as follows:
Insert picture description here
  As shown in the figure above, the 4.0.52 version of the hessian package has introduced the serializers and deserializers files.
  The contents of the deserializers file are as follows:

java.io.File=com.caucho.hessian.io.FileDeserializer
java.math.BigDecimal=com.caucho.hessian.io.BigDecimalDeserializer
javax.management.ObjectName=com.caucho.hessian.io.ObjectNameDeserializer

  The content of the serializers file is as follows:

com.caucho.hessian.io.HessianRemoteObject=com.caucho.hessian.io.RemoteSerializer
com.caucho.burlap.io.BurlapRemoteObject=com.caucho.hessian.io.RemoteSerializer
java.io.File=com.caucho.hessian.io.StringValueSerializer
java.math.BigDecimal=com.caucho.hessian.io.StringValueSerializer
java.util.Locale=com.caucho.hessian.io.LocaleSerializer
javax.management.ObjectName=com.caucho.hessian.io.StringValueSerializer

Guess you like

Origin blog.csdn.net/piaoranyuji/article/details/108342820