From eb042f0f3140bf01a616597d6d0abe79b77ec845 Mon Sep 17 00:00:00 2001 From: Ian Allen Date: Wed, 3 Jan 2024 10:41:27 -0400 Subject: [PATCH] Fix error with Failed to convert value of type by adding a @InitBinder --- .../org/fao/geonet/api/links/LinksApi.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/services/src/main/java/org/fao/geonet/api/links/LinksApi.java b/services/src/main/java/org/fao/geonet/api/links/LinksApi.java index a3141517fe6..46f17469977 100644 --- a/services/src/main/java/org/fao/geonet/api/links/LinksApi.java +++ b/services/src/main/java/org/fao/geonet/api/links/LinksApi.java @@ -25,6 +25,8 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import com.google.gson.Gson; + import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; @@ -63,6 +65,7 @@ import org.springframework.jmx.export.naming.SelfNaming; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; +import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @@ -71,6 +74,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; + +import java.beans.PropertyEditorSupport; import java.io.IOException; import java.sql.SQLException; import java.util.ArrayDeque; @@ -445,6 +450,22 @@ private MAnalyseProcess getRegistredMAnalyseProcess() { return mAnalyseProcess; } + @InitBinder + public void initBinder(WebDataBinder dataBinder) { + dataBinder.registerCustomEditor(LinkFilter.class, new PropertyEditorSupport() { + Object value; + @Override + public Object getValue() { + return value; + } + + @Override + public void setAsText(String text) throws IllegalArgumentException { + value = new Gson().fromJson(text, LinkFilter.class); + } + }); + } + private static class LinkFilter { private String url; private String lastState;