Vitalii T
Vitalii T

Reputation: 508

How to post object with Set/Array field in typescript/angular

I have class like:

export class LogModel {
..
componentSet: Set<string>;
constructor(componentSet: Set<string>) {
    this.componentSet = componentSet;
}

And I need to post this class to Spring boot app. But I have the problem with JSON deserialization because: enter image description here

And I have to use transform method like

`private toArray(set) {
        let array: string[] = [];
        for (let i = 0; i < set.length; ++i)
            array[i] = set[i];
        return array;
    }`

in order to have enter image description here How to properly POST this class?

Upvotes: 0

Views: 322

Answers (1)

Sheik Althaf
Sheik Althaf

Reputation: 1605

Do like this before sending to post method

const postValue = Array.from(this.componentSet);

(OR)

const setValues = this.componentSet.values();
const postValue = Array.from(setValues);

Then post the postValue

Upvotes: 1

Related Questions