Skip to content

Commit

Permalink
Fix error with Failed to convert value of type by adding a @InitBinder
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwallen committed Jan 3, 2024
1 parent 57e0f74 commit eb042f0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions services/src/main/java/org/fao/geonet/api/links/LinksApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit eb042f0

Please sign in to comment.