Home > Software engineering >  Quarkus uses wrong json brackets
Quarkus uses wrong json brackets

Time:09-09

I'm new to Quarkus and now writing a small application (quarkus, psql). I wrote two microservices. One for user data and another for points data. User app return data in correct json format

{
    "username": "mishamba",
    "publicName": "misha",
    "email": "[email protected]",
    "createdOn": "2022-08-28T19:03:53.537 00:00"
}

But point app return data in this format.

Location(id=2, coordinate=(45.0, 50.0), title=fish store, description=Greatest fish store in city, graphicMaterialPath=null, address=Chargaly 79, creatorUsername=mishamba, createdOn=2022-09-05 17: 03: 20.910009, lastUpdateDate=null)

Just as string. How to fix it and make app return correct json.

Here is code samples

Entity class:

@Entity
@RequiredArgsConstructor
@Table(name = "locations")
@Data
@EqualsAndHashCode
@ToString
@TypeDef(name = "psqlPoint", typeClass = PGPointUserType.class)
public class Location {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    @NotNull
    @Column(name = "coordinate")
    @Type(type = "psqlPoint")
    private PGpoint coordinate;
    @NotNull
    private String title;
    private String description;
    @Column(name = "graphic_materials_path")
    @Type(type = "com.pointer.util.psql.type.GenericArrayUserType")
    private List<String> graphicMaterialPath;
    private String address;
    @NotNull
    @Column(name = "creator_username")
    private String creatorUsername;
    @Column(name = "creation_date")
    private Date createdOn;
    @Column(name = "last_update_date")
    private Date lastUpdateDate;
}

Endpoint:

@Path("/v1/locations")
@ApplicationScoped
@AllArgsConstructor
@Produces(value = "application/json")
public class LocationController {

private LocationService locationService;

@GET
@Path("/{locationId}")
public Response getLocationById(@PathParam("locationId") Integer locationId) {
    Location location = locationService.getLocation(locationId);
    return Response.ok(location).build();

...

CodePudding user response:

Just add this dependency.

<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>
  • Related