I am storing an object in RavenDB that has a reference to another object. I wish to indicate to the RavenDB serializer that it should be a reference, not an embedded object. The way to do this is to decorate it with [JsonObject(IsReference = true)] attribute. This is fine, however it means that I have to reference the Raven.Imports.Newtonsoft.Json assembly in my POCO assembly.
So the question is, is there another way to apply this attribute? Perhaps using DefaultContractResolver somehow?
Many thanks for any help.
You can handle that using a contract resolver yes. You can customize the contract resolvers in the RavenDB Conventions.
Related
I have a requirement to map source and target object using mapstruct in a springboot project. Object has more than 700 fields and field names are completely different in both source and target object. Rather than mapping it in interface using "#Mapping", i would like to do it using "JsonProperty / JsonAlias" annotation. Is't possible to do it? and if yes can anyone please let me know on how to do it? any reference example.
I don't find any blogs or article with proper explanation on this.
Regards
Raj
I am developing an application system that has multiple executable applications on different platforms (java and .net).
For communication between them I am using JSON format. So I need to map object to and from json very frequently. Current solution (seems workaround) is jackson at java end and Newtonsoft.Json at .NET end. Problem is property name are not same and not all properties will be required at de-serialization end
So my questions are:
1. Is there any mapper to do this.
Currently using NewtonSoft.JSON.DatasetMapper at .Net end and
jsonanysetter annotation at java, but in this approach mapping
definition is loaded for each object as actual object mapping code
is in code. For example:
//C#
myobj.prop1 = dataSet.Tables[0].Rows[0]["propertyName1"].ToString();
// and so on.....
//Java
switch(key)
{
case "prop1":
myobj.setPropery1(value.toString());
break;
//and so on......
}
2. Object transformationRate needs to be very high as object are
sent and recieved at very high speed. say some 10k objects per second.
We used GSON in one of our project , i think this reference may help you, Apart from it ,there is a similar question may help you. another q/a in stackoverflow
You should take a look at Jackson. It's the de facto JSON library for Java and will happily handle turning objects into JSON and back again. It has many options to allow you to alter the output, and most per-object configuration is carried out using annotations so is visible in your model rather than hidden away in a separate configuration file.
I am using Plinqo and Linq-to-SQL to implement a repository. I'd like to inform the UI of validation rules by examining metadata and acting accordingly. Problem is, the Metadata classes in Plinqo are marked internal and are nested inside the classes they decorate.
How can I get at these classes and enumerate their attributes from another assembly?
The only way that I'm aware of accomplishing this is to use Reflection. The following code uses reflection and looks for all of the rule's attributes defined on the internal metadata class. DynamicData also does a similar lookup of the attributes defined in the Metadata class by using an attribute defined on the class that can be found in the generated partial class:
[System.ComponentModel.DataAnnotations.MetadataType(typeof(PetShop.Data.Category.Metadata))]
Thanks
-Blake Niemyjski
in C#.net, Can i pass a DataContext object (created by LINQ to SQL) as a parameter of a method in another class ?
You can if the project that the class is defined in references the project the dataContext object is created in.
Those DataContext objects are auto-generated however and aren't necessary a good dependency to add to your other "concrete" classes.
I'd just translate the data in the dataContext into a concrete business object and pass that it into your class as a parameter to your method.
The DataContext is just reference to your model interface. Passing it as a reference is useless since you can instantiate it whenever you want and this approach would even confuse other developers.
"First of all, passing a ref variable is used to be able to change variable that holds the reference. But since you are not changing the DataContext dbase reference in your GetPByRole method, passing it as a ref is useless and would even confuse other developers. Perhaps you misunderstand value types and reference types. Reference types (such as DataContext) are always passed by reference, passing it around through method calls will not make new copies of the object itself, merely copies of the reference (which is a 32 or 64 bits value)."
Check this answer: https://stackoverflow.com/a/5248024/5878893
I have an object with a NameValueCollection property which I'm managing with Linq2SQL. I was going to serialise it to an XML column (xelement) in the DB. My problem is I don't really have a hook to convert it to XML on save with Linq2SQL. I believe I can use the OnLoaded partial method to control the deserialisation.
Does anybody have a good method for reference types being persisted into an XML column with Linq2SQL? I don't want to have to create a new table for this property.
Thanks!
I solved this by using the OnLoaded() and OnValidate() extension methods to load and serialise my reference types into an XElement object. This seems to have worked quite well and I now have a method to save a NameValueCollection to our database.