Inconsistent property case after serialization

Discussão em 'Angular' iniciado por ormai, Março 28, 2025.

  1. ormai

    ormai Guest

    I have these two interfaces

    interface Country {
    name: string,
    flag: string,
    code: string,
    dialCode: number
    }

    interface RegisterRequest {
    email: string,
    name: string,
    surname: string,
    password: string,
    rememberMe: boolean,
    country: Country
    }


    then I have a field

    protected form = {} as RegisterRequest;


    finally I do

    this.http.post('/auth/register', this.form).subscribe(...);


    The request body looks like this

    {
    "name": "John",
    "surname": "Doe",
    "country": {
    "name": "Burundi",
    "flag": "",
    "code": "BI",
    "dial_code": 257
    },
    "email": "john.doe@example.org",
    "password": "password",
    "rememberMe": true
    }


    dialCode becomes dial_code, while rememberMe doesn't change.

    On the backend (Spring Boot) I have to manually map the field to the property name with @JsonProperty("dial_code").

    Why does this happen? What's the best way to handle it? Or am I just doing something wrong?

    Continue reading...

Compartilhe esta Página