Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8301949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:09:56+00:00 2026-06-08T17:09:56+00:00

I am using OpenRasta provide an API for my .NET application. I have a

  • 0

I am using OpenRasta provide an API for my .NET application.

I have a problem with the format of the JSON it produces when using Dictionaries.

I have the following config:

 ResourceSpace.Has.ResourcesOfType<Dictionary<String,String>>()
.AtUri("/test")
.HandledBy<ProductHandler>()
.AsXmlDataContract()
.And.AsJsonDataContract();

The ProductHandler returns the following Dictionary:

        Dictionary<String, String> dict = new Dictionary<string, string>();
        dict.Add("foo1", "bar1");
        dict.Add("foo2", "bar2");
        dict.Add("foo3", "bar3");

I would like the following JSON:

{
    "foo1": "bar1",
    "foo2": "bar2",
    "foo3": "bar3"
}

But instead I get the following:

[
    {
        "Key": "foo1",
        "Value": "bar1"
    },
    {
        "Key": "foo2",
        "Value": "bar2"
    },
    {
        "Key": "foo3",
        "Value": "bar3"
    }
]

Any suggestions how to fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:09:57+00:00Added an answer on June 8, 2026 at 5:09 pm

    I ended up using the Newtonsoft.Json library for serialization, which provides the format I wanted.

    The code for the codec is:

    [MediaType("application/json;q=0.3", "json")]
    [MediaType("text/html;q=0.3", "html")]
    public class NewtonsoftJsonCodec : IMediaTypeReader, IMediaTypeWriter
    {
        public object Configuration { get; set; }
    
        public object ReadFrom(IHttpEntity request, IType destinationType, string destinationName)
        {
            using (var streamReader = new StreamReader(request.Stream))
            {
                var ser = new JsonSerializer();
    
                return ser.Deserialize(streamReader, destinationType.StaticType);
            }
    
        }
    
        public void WriteTo(object entity, IHttpEntity response, string[] parameters)
        {
            if (entity == null)
                return;
            using (var textWriter = new StreamWriter(response.Stream))
            {
                var serializer = new JsonSerializer();
                serializer.NullValueHandling = NullValueHandling.Include;
                serializer.Serialize(textWriter, entity);
            }
        }
    }
    

    And the config looks like:

    ResourceSpace.Uses.UriDecorator<ContentTypeExtensionUriDecorator>();
    ResourceSpace.Has.ResourcesOfType<MeasurementDataFile[]>()
        .AtUri("/test")
        .HandledBy<MeasurementHandler>()
        .TranscodedBy<NewtonsoftJsonCodec>()
        .And.AsXmlDataContract();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using OpenRasta 2.0.3214.437 in an ASP.NET 4 web application. I'm registering a custom
We are creating ReST Web Services using ASP.NET and OpenRasta. Is there any tool
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
I'm using Openrasta framework. I've simple POCO which is used in my API and
I'm using OpenRasta framework in a .net service and I've a method as below
Using boost python I need create nested namespace. Assume I have following cpp class
I'm creating a pretty simple HTTP service using OpenRasta. For HEAD requests, the HTTP
(I'm also asking this on the OpenRasta google group) Hey all, I've been using
We just started a greenfield project. A part of requirements is to provide application
I want to implement file upload in RESTful way using openrasta but not able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.