79449019

Date: 2025-02-18 16:47:23
Score: 3.5
Natty:
Report link

I have the same issue currently. My hottest of hotfixes overrode the default serialization of the Link object with this serializer.

public class LinkDecodingSerializer extends JsonSerializer<Link> {

  @Override
  public void serialize(Link value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
    /*
     *  {
     *    "relationName": {
     *      "href":  "http://localhost:69420/@cool@/api"
     *    }
     *  }
     */
    gen.writeStartObject();
    gen.writeStringField("href", UriUtils.decode(value.getHref(), StandardCharsets.UTF_8));
    gen.writeEndObject();
  }
}

Unfortunately I then discovered that that there is an internal HalLink wrapper of the Link class which made the end result look like

    
      "link": {
        "relationName": {
          "href":  "http://localhost:69420/@cool@/api"
        }
      }

This was also a problem so I had to add a HalLink serializer implementation which worked with reflection because HalLink is hidden internal class. I am currently looking for a more intelligent solution

Reasons:
  • Blacklisted phrase (1): I have the same issue
  • Long answer (-1):
  • Has code block (-0.5):
  • Me too answer (2.5): I have the same issue
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Камен Христов