Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

There are some Entities with composite Primary Keys and these entities when exposed are having incorrect Links having full qualified name of classes in URL inside _links

Also clicking on links gives such errors -

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type java.lang.String to type com.core.connection.domains.UserFriendshipId

I have XML configured Spring Repository with jpa:repositories enabled and Respository extending from JpaRepository

Can I make Repository implement org.springframework.core.convert.converter.Converter to handle this. Currently getting links as below -

_links: {
userByFriendshipId: {
href: "http://localhost:8080/api/userFriendships/com.core.connection.domains.UserFriendshipId@5b10/userByFriendId"
}

in xml config , I have jpa:repositories enabled and @RestResource enabled inside Repositories

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
383 views
Welcome To Ask or Share your Answers For Others

1 Answer

At first you need to get a usable link. Currently your composite id is exposed as com.core.connection.domains.UserFriendshipId@5b10. It should be enough to override the toString method of UserFriendshipIdto produce something useful like 2-3.

Next you need to implement a converter so that 2-3 can be converted back to a UserFriendshipId:

class UserFriendShipIdConverter implements Converter<String, UserFriendshipId> {

  UserFriendShipId convert(String id) {
    ...
  }
}

Finally you need to register the converter. You already suggested to override configureConversionService:

protected void configureConversionService(ConfigurableConversionService conversionService) {
   conversionService.addConverter(new UserFriendShipIdConverter());
} 

If you prefer a XML configuration you can follow the instructions in the documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...