Jackson JSON Formatter在Spring中使用it-Prefix更改字段名

时间:2017-05-19 14:32:08

标签: json spring

我有一个JPA Entity类,它将呈现为JSON。 我的问题是JSON Formatter以某种方式重命名前缀为is的字段。在此示例中,字段isMale将更改为male

这是我的班级

// this is kotlin code
@Entity
class RegistrationRequest(
        @Id
        @GeneratedValue
        var id: Long,

        @Column(nullable = false)
        var firstname: String,

        @Column(nullable = false)
        var lastname: String,

        @Column(nullable = false)
        var isMale: Boolean,

        @Column(nullable = false)
        var church: String,

        @Column(nullable = false)
        var language: String,

        @Column(nullable = false)
        var email: String,

        @Column(nullable = false)
        var address: String,

        @Column(nullable = false)
        var country: String,

        @Column(nullable = false)
        var phone: String,

        @Column(nullable = false)
        var jobIsFulltimeStudent: Boolean,

        @Column(nullable = false)
        var jobIsTrainee: Boolean,

        @Column(nullable = false)
        var jobIsUnemployed: Boolean,

        var comment: String,

        @Column(nullable = false)
        var eventCode: String,


        @Column(nullable = false, updatable = false)
        var insertDate: Date,

        @Column(nullable = false)
        var isDeleted: Boolean = false

){
        @PrePersist
        protected fun onCreate() {
                insertDate = Date()
        }
}

这是生成输出的示例

{
  "id": 16,
  "firstname": "Bob",
  "lastname": "Marley",
  "church": "xyz",
  "language": "de",
  "email": "local@host.com",
  "address": "Exampleway 23, 8000 Zurich",
  "country": "Switzerland",
  "phone": "012323434",
  "jobIsFulltimeStudent": false,
  "jobIsTrainee": true,
  "jobIsUnemployed": true,
  "comment": "test",
  "eventCode": "NL17",
  "insertDate": 1495204099746,
  "male": false,
  "deleted": false
}

如果我尝试使用注释@JsonProperty("jsonFieldName"),那么我会收到此异常:

{
  "timestamp": 1495192430037,
  "status": 415,
  "error": "Unsupported Media Type",
  "exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
  "message": "Content type 'application/json;charset=UTF-8' not supported",
  "path": "/registrations"
}

任何想法如何保存我的字段名?

0 个答案:

没有答案