Home > database >  Internal Server Error 500 The given string value cannot be transformed to Json object
Internal Server Error 500 The given string value cannot be transformed to Json object

Time:05-11

error: "Internal Server Error"

message: "The given string value: {\"raDate\": null, \"deleted\": [100722859, 100722860, 100722861, 100722862, 100722863, 100722864, 100722865, 100722866, 100722870, 100722871, 100722872], \"inserted\": [110024074, 110024075, 110024076, 110024077, 110024078, 110024079, 110024080, 110024081, 110024085, 110024086, 110024087], \"baselineDate\": \"2020-08-11 07:00:00Z\"} cannot be transformed to Json object; nested exception is java.lang.IllegalArgumentException: The given string value: {\"raDate\": null, \"deleted\": [100722859, 100722860, 100722861, 100722862, 100722863, 100722864, 100722865, 100722866, 100722870, 100722871, 100722872], \"inserted\": [110024074, 110024075, 110024076, 110024077, 110024078, 110024079, 110024080, 110024081, 110024085, 110024086, 110024087], \"baselineDate\": \"2020-08-11 07:00:00Z\"} cannot be transformed to Json object"

path: "/api/marathon/baselineTools/baselineHistory"

status: 500

@RequestMapping(value = "baselineHistory", method = RequestMethod.POST)
    @PreAuthorize("isFullyAuthenticated() && (hasRole('ROLE_ADMIN') || hasRole('ROLE_BASELINETOOLS'))")
    public List<BaselineHistory> getBaselineHistory(@RequestBody BaselineData data) {
        int reportingProjectId = data.getReportingProjectId();
        String phase = data.getPhase();

        return this.baselineHistoryRepository.findAllByReportingProjectIdAndPhase(reportingProjectId, phase);
    }


import java.time.ZoneId;
import java.time.ZonedDateTime;
import com.fasterxml.jackson.annotation.JsonFormat;

import javax.annotation.Nullable;

public class BaselineData {

    private int reportingProjectId;
    private String activityId;
    private String phase;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ssX")
    @Nullable
    private ZonedDateTime date;

    public BaselineData() {
    }

    public int getReportingProjectId() {
        return reportingProjectId;
    }

    public String getActivityId() {
        return activityId;
    }

    public String getPhase() {
        return phase;
    }

    @Nullable
    public ZonedDateTime getDate() {
        return date != null ? date.withZoneSameInstant(ZoneId.of("Z")) : null;
    }

    public void setDate(ZonedDateTime date) {
        this.date = date.withZoneSameInstant(ZoneId.of("Z"));
    }
}

Getting the following error on a POST from React frontend to Java Spring backend with a 500 server error. I have seen some posts about serializing the backend controller endpoint would that work for a POST? Above are the Java Pojo and controller classes.

CodePudding user response:

You need to look at the backend (server) error to find the real problem. Does your sent Json matches exactly the java Object you are deserializing to ? if not you need a custom deserializer

CodePudding user response:

If you can share BaselineData class. it will help to find out the problem.

  • Related