Skip to content

Conversation

maca88
Copy link
Contributor

@maca88 maca88 commented Jul 5, 2018

This PR adds a new shared library NHibernate.Cache.Common, proposed by @fredericDelaporte which allows to share the new ICacheSerializer interface among distributed cache providers and also adds a NHibernate.Caches.Util.JsonSerializer library containing a json serializer by using Json.NET.
I've tested the json serializer with the NHiberante tests successfully (master branch), by configuring the serializer as:

_serializer = new JsonCacheSerializer();
_serializer.RegisterType(typeof(string[]), "sa");
_serializer.RegisterType(typeof(NHSpecificTest.NH2392.PhoneNumber), "pn");
_serializer.RegisterType(typeof(NHSpecificTest.NH2394.PhoneNumber), "pn2");
_serializer.RegisterType(typeof(NHSpecificTest.NH3874.IntWrapper), "iw");
_serializer.RegisterType(typeof(NHSpecificTest.EntityWithUserTypeCanHaveLinqGenerators.BarExample), "bar");
_serializer.RegisterType(typeof(NHSpecificTest.EntityWithUserTypeCanHaveLinqGenerators.FooExample), "foo");
_serializer.RegisterType(typeof(NullableInt32), "nint", jsonContract =>
{
  // Use fields instead of properties
  var contract = (JsonObjectContract) jsonContract;
  contract.Properties.Clear();
  var properties = typeof(NullableInt32).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                      .Select(f => new JsonProperty
                      {
                        PropertyName = f.Name,
                        PropertyType = f.FieldType,
                        DeclaringType = f.DeclaringType,
                        ValueProvider = new ReflectionValueProvider(f),
                        AttributeProvider = new ReflectionAttributeProvider(f),
                        Readable = true,
                        Writable = true

                      });
  foreach (var property in properties)
  {
    contract.Properties.AddProperty(property);
  }
}, typeof(JsonObjectContract)); // Because of the TypeConverter attribute, the default resolved json contract for NullableInt32 is JsonStringContract.

TODO:

  • Wait for the NHibernate 5.2 release and update the code

@fredericDelaporte fredericDelaporte added this to the 5.5 milestone Jul 6, 2018
@fredericDelaporte

This comment has been minimized.

@maca88

This comment has been minimized.

@fredericDelaporte
Copy link
Member

I have rebased this. The only updates required for compiling were unrelated obsolete fixes.

Had you in mind other changes to do?

And some cleanup
@maca88
Copy link
Contributor Author

maca88 commented Dec 5, 2018

Had you in mind other changes to do?

Yes there are some TODOs in this PR that I intend to do. I'm going to do them now.

@maca88 maca88 changed the title WIP Common cache serializer and json serializer Common cache serializer and json serializer Dec 5, 2018
@maca88
Copy link
Contributor Author

maca88 commented Dec 5, 2018

Done all the changes that I planned to do.

@fredericDelaporte fredericDelaporte merged commit 2657d9b into nhibernate:master Dec 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants