uuuyuqi commented on issue #104:
URL: 
https://github.com/apache/dubbo-hessian-lite/issues/104#issuecomment-4168758452

   ### Proposed Solution / 建议的解决方案
   
   Pre-register `LocaleHandle` (and other Hessian built-in wire types) in 
`_staticTypeMap` within `SerializerFactory`, so they no longer depend on the 
business class loader.
   
   在 `SerializerFactory` 的 `_staticTypeMap` 中预注册 `LocaleHandle`(以及其他 Hessian 
内置的 wire type),使它们不再依赖业务类加载器。
   
   **Why this works / 为什么可行:**
   
   Looking at [`getDeserializer(String 
type)`](https://github.com/apache/dubbo-hessian-lite/blob/master/src/main/java/com/alibaba/com/caucho/hessian/io/SerializerFactory.java#L647-L698):
   
   ```java
   // Line 662-664: First check _staticTypeMap
   deserializer = (Deserializer) _staticTypeMap.get(type);
   if (deserializer != null)
       return deserializer;
   
   // Line 676: Only call loadSerializedClass if not found in _staticTypeMap
   Class cl = loadSerializedClass(type);
   ```
   
   If `LocaleHandle` is pre-registered in `_staticTypeMap`, the deserializer 
will be returned directly without calling `loadSerializedClass()`, thus 
avoiding the class loader issue.
   
   如果 `LocaleHandle` 预注册在 `_staticTypeMap` 中,反序列化器会直接返回,不会调用 
`loadSerializedClass()`,从而避免类加载器问题。
   
   **Example implementation / 实现示例:**
   
   ```java
   // In SerializerFactory static block
   _staticTypeMap.put("com.alibaba.com.caucho.hessian.io.LocaleHandle", 
       new JavaDeserializer(LocaleHandle.class));
   ```
   
   **Other Handle types to consider / 需要考虑的其他 Handle 类型:**
   
   - `CalendarHandle`
   - `BitSetHandle`
   - `EnumSetHandler`
   - Java8 time handles (`DurationHandle`, `InstantHandle`, `LocalDateHandle`, 
`LocalDateTimeHandle`, `LocalTimeHandle`, `MonthDayHandle`, 
`OffsetDateTimeHandle`, `OffsetTimeHandle`, `PeriodHandle`, `YearHandle`, 
`YearMonthHandle`, `ZoneOffsetHandle`, `ZonedDateTimeHandle`)
   
   This approach is clean and follows the existing design pattern of 
`_staticTypeMap`.
   
   这个方案简洁且符合 `_staticTypeMap` 现有的设计模式。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to