question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Probleme with OnDeserialize when multiple array

See original GitHub issue

Information

  • Version: 6.59.2
  • Packages:
    "@tsed/ajv": "6.59.2",
    "@tsed/common": "6.59.2",
    "@tsed/core": "6.59.2",
    "@tsed/di": "6.59.2",
    "@tsed/exceptions": "6.59.2",
    "@tsed/json-mapper": "6.59.2",
    "@tsed/platform-express": "6.59.2",
    "@tsed/schema": "6.59.2",
    "@tsed/swagger": "6.59.2",
    "@tsed/typeorm": "6.43.0",

The object I want to deserialize contain 2 attributes which array array of typed object. But in the OnDeserialize I get the 2 array mixed.

Example

// in foo.ts
import { OnDeserialize } from '@tsed/json-mapper';

export class Foo {
  @CollectionOf(String)
  @OnDeserialize(features => {
    console.log('features:', features);
    return features;
  })
  features: string[];
  @CollectionOf(String)
  @OnDeserialize(filters => {
    console.log('filters:', filters); 
    return filters;
  })
  filters: string[];
}

// In bar.controller.ts
@Controller('/bar')
@MergeParams()
export class BarController {
  @Post('')
  async createFoo(
    @Required() @BodyParams() foo: Foo
  ): Foo {
    return foo; 
  }

When I do POST - http://localhost:3000/foo with this body :

{
	"features": ["feature1", "feature2"],
	"filters": ["filter1", "filter2"]
}

Here is my console output:

features: [ 'feature1', 'feature2', 'filter1', 'filter2' ]
filters: [ 'feature1', 'feature2', 'filter1', 'filter2' ]
features: [ 'feature1', 'feature2', 'filter1', 'filter2' ]
filters: [ 'feature1', 'feature2', 'filter1', 'filter2' ]

Acceptance criteria

  • OnDeserialize should get only the data associated with the named property
  • OnDeserialize should be call only one time by property

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

1reaction
TakeshiDaveaucommented, Jul 22, 2021

Hello @Romakita

Thanks for your answer, I’ll check this, maybe something specific we’ve added to our project create this bug.

I’ll let you know when I have more information.

Bye Takeshi

1reaction
Romakitacommented, Jul 20, 2021

Hello @TakeshiDaveau I’ll try to fix this issue tomorrow 😉

see you Romain

Read more comments on GitHub >

github_iconTop Results From Across the Web

WCF Serialization Error on HPC - multidimensional array
Trying to serialize some other kind of non serializable object (such as an Exception). To prevent the item from being serialized apply [ ......
Read more >
OnDeserialized attribute from NS2 causes runtime error in full ...
Several CSLA base classes use the OnDeserialized attribute to be notified when the BinaryFormatter or NDCS has completed deserializing the ...
Read more >
Bug - Error displaying nested arrays in the inspector
After the transition to 2020.3.6, there was a problem with displaying nested arrays if there are more than two of them in the...
Read more >
c# - Deserializing JSON when sometimes array and ...
Without using the FacebookMediaJsonConverter, I get an error: Cannot deserialize JSON object into type 'System.Collections.Generic.List`1[FacebookMedia]'. which ...
Read more >
was outside the bounds of the array." error with CSLA 3.5 Beta 1
I try with an override of OnDeserialized() now, but it doesn't solve the problem. Maybe I have a some bug in my classes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found