You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The MessagePack constructor could work with this type of objects only if I use SerializationConstructor. It is fine for my own objects, but if I try to serialize internal Akka objects with ContractlessStandardResolver, I will get an error.
Another option is to create a separate Formatter for each internal singleton message
What kind of effect is expected, serializer can not deserialize that have only private constructors.
Of course you can not set it to static private property.
If necessary, please make custom serializer.
publicclassRecoveryCompletedFormatter:IMessagePackFormatter<RecoveryCompleted>{publicintSerialize(refbyte[]bytes,intoffset,RecoveryCompletedvalue,IFormatterResolverformatterResolver){// TODO:as you like}publicRecoveryCompletedDeserialize(byte[]bytes,intoffset,IFormatterResolverformatterResolver,outintreadSize){// force create object...varuninitializedObject=System.Runtime.Serialization.FormatterServices.GetUninitializedObject(typeof(RecoveryCompletedFormatter));// set from bytes...// Of course can not set, but use reflection, can set...// RecoveryCompleted.Instance = uninitializedObject;}}
Utf8Json supports this feature, I found how to implements completely smart and keep performance way.
But MessagePack-Csharp needs a little refactoring.
Anyway, I know what to do, so I will finish it.
Hi, I'm trying to use this library to deal with private constructors.
I have made the following unit test:
public class UnitTest1
{
public T SerializeDeserialize<T>(T obj)
{
var serialized = MessagePackSerializer.Serialize(obj, ContractlessStandardResolverAllowPrivate.Instance);
var unserialized =
MessagePackSerializer.Deserialize<T>(serialized, ContractlessStandardResolverAllowPrivate.Instance);
return unserialized;
}
public class TestType
{
public static TestType Create(int initial)
{
var t = new TestType();
t.Val = initial;
return t;
}
private TestType() { }
private int val;
public int Val
{
get { return val; }
private set { val = value; }
}
}
[Fact]
public void TestPrivateTestType()
{
var testType = TestType.Create(42);
var actual = SerializeDeserialize(testType);
Assert.Equal(testType.Val, actual.Val);
}
}
This test fails with MessagePack.Internal.MessagePackDynamicObjectResolverException : can't find public constructor.
I'm using MessagePack v1.7.3.4.
Am I using this incorrectly? my understanding from this issue is that the TestType should serializable and deserializable.
IIRC what I found was that "AllowPrivate" on this MessagePack library only means access to private fields/members, but does not check for private constructors.
Not sure if that helps y'all, but I thought I'd add that in. I ended up making all my constructors public for the time being (though my code base is only myself, so I can enforce my own good practices).
Activity
[-]Singleton objects with private constructor[/-][+]Singleton objects with a private constructor[/+]neuecc commentedon Apr 10, 2017
What kind of effect is expected, serializer can not deserialize that have only private constructors.
Of course you can not set it to static private property.
If necessary, please make custom serializer.
This can not be generalized.
alexvaluyskiy commentedon Apr 11, 2017
JSON.NET supports a private constructor via
ConstructorHandling.AllowNonPublicDefaultConstructor. Wire also supports itneuecc commentedon Apr 11, 2017
Is it OK to understand that Singleton is irrelevant?
alexvaluyskiy commentedon Apr 11, 2017
Yes, singleton was an inappropriate example. It is all about
private constructor[-]Singleton objects with a private constructor[/-][+]support private constructor, members[/+]neuecc commentedon Apr 11, 2017
Okay.
I know how to handle private constructors and private members as fast.
I'll implement it.
alexvaluyskiy commentedon Jun 8, 2017
It does not support internal members too
israellot commentedon Jun 13, 2017
I think using private setters for properties is a good start.
megakid commentedon Oct 4, 2017
Any progress on this? This is a blocker for us using this superb library.
neuecc commentedon Oct 5, 2017
Utf8Json supports this feature, I found how to implements completely smart and keep performance way.
But MessagePack-Csharp needs a little refactoring.
Anyway, I know what to do, so I will finish it.
megakid commentedon Oct 5, 2017
Awesome work - Really nice job on the UTF8Json library as well.
neuecc commentedon Oct 9, 2017
I've release
v1.7.0, it includes this feature.you can use new resolvers,
StandardResolverAllowPrivateorContractlessStandardResolverAllowPrivate.megakid commentedon Oct 10, 2017
Nice work. Thanks
tylerhartwig commentedon Oct 30, 2018
Hi, I'm trying to use this library to deal with private constructors.
I have made the following unit test:
This test fails with
MessagePack.Internal.MessagePackDynamicObjectResolverException : can't find public constructor.I'm using MessagePack v1.7.3.4.
Am I using this incorrectly? my understanding from this issue is that the
TestTypeshould serializable and deserializable.qstarin commentedon Nov 17, 2018
I'm experiencing the same behavior as tylerhartwig with MessagePack v1.7.3.4.
MessagePackSerializer.Serialize(value, MessagePack.Resolvers.StandardResolverAllowPrivate.Instance);fails withMessagePack.Internal.MessagePackDynamicObjectResolverException : can't find matched constructor.If I make the constructor public, it works fine.
CheeryProgrammer commentedon Mar 15, 2019
SerializationConstructorAttribute does not help :(
tylerhartwig commentedon Mar 22, 2019
IIRC what I found was that "AllowPrivate" on this MessagePack library only means access to private fields/members, but does not check for private constructors.
Not sure if that helps y'all, but I thought I'd add that in. I ended up making all my constructors public for the time being (though my code base is only myself, so I can enforce my own good practices).
Merge pull request #40 from AArnott/reader
Merge pull request #40 from AArnott/sdkRefUpdates