Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: [serializr] this value is not primitive: [object Object], can't figure out what's next #163

Open
redhatpanda opened this issue Jul 24, 2022 · 4 comments

Comments

@redhatpanda
Copy link

redhatpanda commented Jul 24, 2022

So I have a model which is as such:

export default class VendorProduce {
    @ serializable(identifier())
    public id = uuidv4()

    @serializable
    public vendorId: string

    @serializable
    public produceName: string

    @serializable
    public stockStatus: string

    @serializable
    public minPrice: string

    @serializable
    public maxPrice: string

    @serializable
    public stockCount: string 

    @serializable
    public produceVariants: object

    constructor(
        vendorId: string,
        produceName: string,
        stockStatus: string,
        minPrice: string,
        maxPrice: string,
        stockCount: string,
        produceVariants: {
            variantName: {
                days: string,
                image: string
            }
        }
    ) {
        this.vendorId = vendorId
        this.produceName = produceName
        this.stockStatus = stockStatus
        this.minPrice = minPrice
        this.maxPrice = maxPrice
        this.stockCount = stockCount
        this.produceVariants = produceVariants
        makeAutoObservable(this)
    }

    static validationSchema = yup.object().shape({
        vendorId: yup.string().required('This field is required'),
        produceName: yup.string().required('This field is required'),
        stockStatus: yup.string().required('This field is required'),
        minPrice: yup.string().required('This field is required'),
        maxPrice: yup.string().required('This field is required'),
        stockCount: yup.string().required('This field is required'),
        produceVariants: yup.object().required('This field is required'),
    })
} 

Upon this model getting called during some API Calls I get the following error:
image

I am new to using Serializr and not being able to understand how to fix this.

@mweststrate
Copy link
Member

mweststrate commented Jul 24, 2022 via email

@redhatpanda
Copy link
Author

redhatpanda commented Jul 24, 2022

@mweststrate Hey, thanks for pointing that out!
But i just wanted to know, can we not use non primitive types like object here?
If not, what can be the way out?

@mweststrate
Copy link
Member

mweststrate commented Jul 24, 2022 via email

@paulftw
Copy link

paulftw commented Nov 24, 2023

I think this issue can be closed, because the underlying cause and and a documentation link have been provided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants