ArfokSalameche
ArfokSalameche

Reputation: 11

Katharsis: How to set resource type for jpa entity?

I'm using Katharsis with spring boot for my project, and my problem is with Katharsis-jpa. It seems katharsis ignore @JsonApiResource annotations or does not apply mapping for the type specified.

I've currently two classes : One is my entity User:

@JsonApiResource(type = "users")
@Entity
@Table (name = "users")
@EqualsAndHashCode(of = "firstName")
@NoArgsConstructor
public class User {

    @Getter
    @Setter
    @JsonApiId
    @Id
    @GeneratedValue (strategy = GenerationType.AUTO)
    private Long id;

    @Getter
    @Setter
    @Column
    @JsonProperty (value = "last-name")
    private String lastName;

    @Getter
    @Setter
    @Column
    @JsonProperty (value = "first-name")
    private String firstName;
}

The second is my jpa repository :

@Component
public class UserResourceRepository extends JpaEntityRepository<User, Long>  {

    @Autowired
    public UserResourceRepository(JpaModule module) {
        super(module, JpaRepositoryConfig.create(User.class));
    }
}

Then my application.properties file is the following:

katharsis:
  resourcePackage: my_package_name
  domainName: http://localhost:8080
  pathPrefix: /api
  jpa:
    enabled: false

spring:
  datasource:
    driverClassName: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5432/my_db
    username: my_user
    password: my_password
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true

The problem is in two parts : - the url to get data : http://localhost:8080/users doesn't work, - the field into the json api serialize are in camel case instead of dash

Then, without the katharsis-jpa module (with a simple ResourceRepositoryBase for example) the annotation @JsonApiResource works fine.

Does anyone get an idea on it ?

Upvotes: 1

Views: 519

Answers (0)

Related Questions