Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Remove JsonViewComponentResult #3992

Closed
JamesNK opened this issue Jan 26, 2016 · 6 comments
Closed

Remove JsonViewComponentResult #3992

JamesNK opened this issue Jan 26, 2016 · 6 comments
Assignees
Milestone

Comments

@JamesNK
Copy link
Member

JamesNK commented Jan 26, 2016

I noticed that JsonHelper reuses JsonOutputFormatter for writing JSON but JsonViewComponentResult doesn't. It misses out from array pooling that is managed by the output formatter.

Should JsonViewComponentResult use JsonOutputFormatter?

@danroth27
Copy link
Member

@rynowak Is the JsonHelper supposed to be using the JsonOutputFormatter? I thought we had separated output formatting from all the other JSON use cases.

@Eilon
Copy link
Member

Eilon commented Jan 26, 2016

Looks like we have a variety of behaviors depending on how you do serialization:

  • JsonOutputFormatter/JsonInputFormatter: Get the shared JsonSerializerSettings from the service container.
  • JsonHelper (used in view pages): Creates its own JsonOutputFormatter. Can pass in custom JsonSerializerSettings. Never uses shared settings from the service container.
  • JsonViewComponentResult: Creates its own JsonSerializer. Can pass in custom JsonSerializerSettings, but if none specified, gets the shared JsonSerializerSettings from MvcJsonOptions from the service container.
  • JsonResult: The work is done through the JsonResultExecutor, which is retrieved from the service container, and uses the specified JsonSerializerSettings, but if none specified, gets the shared JsonSerializerSettings from MvcJsonOptions from the service container.

@JamesNK
Copy link
Member Author

JamesNK commented Jan 26, 2016

Only JsonOutputFormatter/JsonInputFormatter are using array pooling.

@rynowak
Copy link
Member

rynowak commented Jan 27, 2016

This has been rehashed like 15 times, and every time it's discussed my suggestion is to remove JsonViewComponentResult. So I'll suggest it again, let's remove JsonViewComponentResult.

If we're still not willing to remove this, let's make it go through one of the other code paths.


JsonHelper (used in view pages): Creates its own JsonOutputFormatter. Can pass in custom JsonSerializerSettings. Never uses shared settings from the service container.

This is not true. No code in JsonHelper instantiates a JsonOutputFormatter. This instance that gets injected by DI is configured to use the shared settings

Let's add the above to the docs in JsonHelper so that it doesn't get asked again.

@Eilon
Copy link
Member

Eilon commented Feb 19, 2016

We've decided to fix the inconsistencies here by removing JsonViewComponentResult because there are no known strong scenarios for it. There are already plenty of ways to write JSON to the result stream and we don't need this one.

@Eilon Eilon changed the title JsonViewComponentResult and JsonOutputFormatter Remove JsonViewComponentResult Feb 19, 2016
@ryanbrandenburg
Copy link
Contributor

Fixed in #4263

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

No branches or pull requests

5 participants