legacy-knowledge-base
公開されました Sep. 10, 2025

JSONFactoryUtil.looseDeserialize メソッドを使用すると、クラスの代わりに HashMap にデシリアライズされます。

written-by

Sergio Alonso

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

legacy-article

learn-legacy-article-disclaimer-text

問題

  • JSONFactoryUtil.looseDeserialize メソッドを使用する WAR ポートレットがあります。
  • また、私たちのクラスはホワイトリストに登録されていると定義されています。 以下を参照してください。
json.deserialization.whitelist.class.names=\
com.liferay.portal.kernel.cal.DayAndPosition,\
com.liferay.portal.kernel.cal.Duration,\
com.liferay.portal.kernel.cal.TZSRecurrence,\
com.liferay.portal.kernel.internal.service.permission.ModelPermissionsImpl,\
com.liferay.portal.kernel.messaging.Message,\
com.liferay.portal.kernel.model.PortletPreferencesIds,\
com.liferay.portal.kernel.security.auth.HttpPrincipal,\
com.liferay.portal.kernel.service.ServiceContext,\
com.liferay.portal.kernel.util.HtmlEscapableObject,\
com.liferay.portal.kernel.util.GroupSubscriptionCheckSubscriptionSender,\
com.liferay.portal.kernel.util.LongWrapper,\
com.liferay.portal.kernel.util.SubscriptionSender,\
com.liferay.portal.kernel.util.SubscriptionSender$HTMLAtributeEscapableObject,\
com.liferay.portal.kernel.util.SubscriptionSender$URIEscapableObject,\
com.liferay.portal.kernel.util.Tuple,\
java.util.GregorianCalendar,\
java.util.Locale,\
java.util.TimeZone,\
sun.util.calendar.ZoneInfo,\
com.acme.MyClass
  • しかし、このメソッドを使用すると、予想どおり com.acme.MyClass ではなく、 HashMap オブジェクトが取得されます。

解像度

  • 期待される結果を得るために利用可能な別の方法があります。
JSONFactoryUtil.deserialize(String json)
  • このメソッドは、プロパティを使用する逆シリアル化手順を提供します
json.deserialization.whitelist.class.names
  • 参照された方法に対して
JSONFactoryUtil.looseDeserialize(String json)

そのプロパティを使用しません。 その結果、デシリアライズ手順は完了しません。

  • したがって、 JSONFactoryUtil.deserialize(String json) メソッドを使用する必要があります。

did-this-article-resolve-your-issue

legacy-knowledge-base