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

  • SEARCH
  • Home
  • 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 8544297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:31:23+00:00 2026-06-11T12:31:23+00:00

I am using Newtonsoft.Json .Net for 4.0 for this project Parent class: public class

  • 0

I am using Newtonsoft.Json .Net for 4.0 for this project

Parent class:

public class CLiveThing
{
    private object lawk = new object();

    public Action<double> hp_cur_changed;
    public Action<double> hp_max_changed;

    public double hp_max { get; private set; }
    public double hp_cur { get; private set; }

    public void change_hp_max(double val)
    {
        lock (lawk)
        {
            hp_max += val;
            if (hp_max_changed != null)
                hp_max_changed(hp_max);
        }
    }

    public void change_hp_cur(double val)
    {
        lock (lawk)
        {
            hp_cur += val;
            if (hp_cur_changed != null)
                hp_cur_changed(hp_cur);
        }
    }
}

Child class:

public class CPlayer : CLiveThing
{
    public int id { get; private set; }

    public CPlayer(int id)
    {
        this.id = id;
    }

    /*
     * Network
    */

    public string Serialize()
    {
        return Newtonsoft.Json.JsonConvert.SerializeObject(this);
    }
    public static CPlayer Deserialize(string val)
    {
        return Newtonsoft.Json.JsonConvert.DeserializeObject<CPlayer>(val);
    }
}

Server (uses Players.CPlayers to manage all players with a generic collection)

Players.CPlayers.Serialize()

Players.CPlayers.Serialize serializes all players in the server’s memory, one per line

Like so:

public static string Serialize()
{
    players_lock.AcquireReaderLock(Timeout.Infinite);
    string str = "";
    foreach (CPlayer player in players.Values)
    {
        str += player.Serialize();
        str += Environment.NewLine;
    }

    players_lock.ReleaseReaderLock();
    return str;
}

Client

I put a break line in the Players.CPlayers.Deserialize loop, which reverses what the server did.

foreach (string line in split)
{
    if (line.Length > 0)
    {
        CPlayer player = CPlayer.Deserialize(line);
        addOrReplace(player.id, player);
    }
}

Here’s an example of one line:

What goes in:

"{\"hp_cur_changed\":null,\"hp_max_changed\":null,\"id\":1,\"hp_max\":100.0,\"hp_cur\":100.0}"

What comes out of CPlayer.Deserialize():

out

It only Deserialized the ID and ignored the properties in the parent class. Which is weird because the server-side did Serialize it properly. Can anyone tell me 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-11T12:31:24+00:00Added an answer on June 11, 2026 at 12:31 pm

    I was not able to find an official reference why it’s working like this but there are at least two way to solve your problem:

    Declare your base class property setters as public

     public double hp_cur { get; set; }
    
     public double hp_max { get; set; }
    

    Or annotate them with the JsonProperty attribute:

     [JsonProperty]
     public double hp_max { get; private set; }
    
     [JsonProperty]
     public double hp_cur { get; private set; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the Newtonsoft.Json library, imagine I have got public class Test { public Object
I'm using Newtonsoft JSON.NET 4.5r7 in an MVC4 non-api project. Below I rename id
I'm using the Newtonsoft JSON.NET package to deserialize my responses. This is a sample
I'm working on a .NET 2.0 C# project using the Newtonsoft.JSON library. When i
Currently I am using the terrific Linq 2 Json.net (by newtonsoft), which is a
I've serialized an object using Newtonsoft's JSON serializer, and the DateTime has come through
I am trying to populate a C# object (ImportedProductCodesContainer) with data using JSON.NET deserialization.
I am using Newtonsoft.Json to Deserialize json string to Object, but I can't judge
I have a working application using Json.NET (newtonsoft) as a custom serializer. Currently I'm
I've been using Json.Net to parse JSON to object and convert to XMLDocument but

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.