json2typescript icon indicating copy to clipboard operation
json2typescript copied to clipboard

Class identifiers is unique but still getting error.

Open mdragoss opened this issue 3 years ago • 4 comments
trafficstars

@JsonObject('City') // Make sure "City" is a unique identifier for this class export class City {}

Get an error Error: Fatal error in JsonConvert. You must use unique class identifiers in the @JsonObject() decorator. Class identifier: City

 "next": "12.2.5",
 "react": "18.2.0",
 "react-dom": "18.2.0",
 "typescript": "4.7.4"

mdragoss avatar Sep 29 '22 09:09 mdragoss

Can you provide a minimal example in a Stackblitz?

I don't think it is possible to get this error with a class definition like above, unless you have a conflict of multiple class names.

andreas-aeschlimann avatar Sep 29 '22 14:09 andreas-aeschlimann

Hello, here is example, can be made some changes after saving getting error. https://stackblitz.com/edit/nextjs-9n54xo?file=pages/index.tsx

mdragoss avatar Sep 30 '22 07:09 mdragoss

I don't know what's going on under the hood with nextjs, but the problem seems that your file hello.ts is loaded twice in this application. I was able to verify this fact by adding a console.log into this file. Thus, the class City is read twice and json2typescript throws the error about not having a unique class City.

If you manage to work around this duplicate loading, you will fix the error.

andreas-aeschlimann avatar Sep 30 '22 23:09 andreas-aeschlimann

Ok, thanks, I should try to play with reactStrictMode enable and disable in next js config.

mdragoss avatar Oct 01 '22 13:10 mdragoss