Using camel case adds id property to JSON document #16529
Answered
by
garayx
marcuslindblom
asked this question in
Q&A
-
I think the id property shouldn't exist in the JSON document but when I use camel case in my db it is always present. Is this a bug? You can check this test out. namespace Test
{
public class IdentityPropertyNameCamelCaseTest : RavenTestDriver
{
private readonly ITestOutputHelper output;
public IdentityPropertyNameCamelCaseTest(ITestOutputHelper output)
{
this.output = output;
}
protected override void PreInitialize(IDocumentStore documentStore)
{
documentStore.Conventions.Serialization = new NewtonsoftJsonSerializationConventions
{
CustomizeJsonSerializer = (serializer) =>
{
serializer.ContractResolver = new CamelCasePropertyNamesContractResolver();
}
};
documentStore.Conventions.PropertyNameConverter = mi => $"{Char.ToLower(mi.Name[0])}{mi.Name.Substring(1)}";
documentStore.Conventions.ShouldApplyPropertyNameConverter = info => true;
}
[Fact]
public void ShouldGetUserResultOnQuery() {
using (var store = GetDocumentStore())
{
using (var session = store.OpenSession())
{
var user = new MyUser {
UserName = "john"
};
session.Store(user, "users/1");
session.SaveChanges();
}
WaitForUserToContinueTheTest(store); //Sometimes we want to debug the test itself, this redirect us to the studio
using (var session = store.OpenSession())
{
var user = session.Query<MyUser>().Where(u => u.UserName == "john").FirstOrDefault();
Assert.NotNull(user);
}
}
}
public class MyUser : MyUserBaseClass {}
public class MyUserBaseClass {
public string Id {get;set;}
public string UserName {get;set;}
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
garayx
May 28, 2023
Replies: 1 comment 5 replies
-
You are not seeing the document id convention, so we can't tell what is it. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it seems like we clear the Id property from json by using the property name which is starting with big letter.
https://issues.hibernatingrhinos.com/issue/RavenDB-20566