小编DPa*_*ncs的帖子

Jackson:防止序列化哈希图获得的json字符串的序列化

我的问题有点类似于防止 GSON 序列化 JSON 字符串,但那里的解决方案使用 GSON 库,而我仅限于使用 Jackson (fasterxml)。

我有一个实体类,如下所示:

package com.dawson.model;

import com.dawson.model.audit.BaseLongEntity;
import lombok.extern.log4j.Log4j;

import javax.persistence.*;

@Table(name = "queue", schema = "dawson")
@Entity
@Log4j
public class Queue extends BaseLongEntity {
    protected String requestType;
    protected String body;

    protected Queue() {
    }

    public Queue(String requestType, String body) {
        this.requestType = requestType;
        this.body = body;
    }

    @Column(name = "request_type")
    public String getRequestType() {
        return requestType;
    }

    public void setRequestType(String requestType) {
        this.requestType = requestType;
    }

    @Column(name = "body")
    @Lob …
Run Code Online (Sandbox Code Playgroud)

java serialization json jackson

1
推荐指数
1
解决办法
1225
查看次数

Spring boot中的GetMapping排除特定路径变量匹配

我有一个带有以下 GetMapping 的控制器

@GetMapping(value = "/dawson/v1/{dataType}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<String> respondWithData(@PathVariable String dataType, @RequestParam(name = "minDate") String min_date, @RequestParam(name = "maxDate") String max_date, @RequestParam(USERID) String user_id, @RequestHeader(value = "Authorization") String authorizationHeader) {
Run Code Online (Sandbox Code Playgroud)

其中 dataType 可以是 String、Map、Object 或 Calendar 之一。我创建了另一个 GetMapping 如下

@GetMapping(value = "/dawson/v1/signInReq")
public ResponseEntity<String> mySignInRequest(@RequestBody Map<String, String> paramMap, HttpServletRequest request, HttpServletResponse response) {
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试访问 /dawson/v1/signInReq 时,它仍然会命中第一个映射,而不是 signInReq 映射。有没有办法排除signInReq作为{dataType}的匹配项?

我确实有在上面的第一个映射中列出所有可能的数据类型的解决方法,但想知道是否有更好的方法来处理它(也许是正则表达式?)。

java spring-boot get-mapping

1
推荐指数
1
解决办法
6474
查看次数

标签 统计

java ×2

get-mapping ×1

jackson ×1

json ×1

serialization ×1

spring-boot ×1