-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug : Mixed Case Keys do not work. Naming Strategy has no effect #45
Comments
Additionally - this means that the default Naming Strategy does not work as designed. |
Consider this test : MixedCaseTest.proto
And this code (ns ticket-portal.services.mixed-case)
(use 'flatland.protobuf.core)
(import 'org.flatland.test.MixedCaseTest$MixedCase)
(def mix-test (protodef MixedCaseTest$MixedCase))
(print (protobuf-schema mix-test))
{:type :struct, :name Data.MixedCase, :fields {:shouldpass {:type :string}, :mightfail {:type :string}}}nil
(def p (protobuf mix-test :shouldpass "pass" :mightfail "fail"))
p
{:shouldpass "pass", :mightfail "fail", :mightfail "fail"}
(def p (protobuf mix-test :shouldpass "pass" :mightFail "fail"))
p
{:shouldpass "pass"} using the "plain" naming strategy (def mix-test (protodef MixedCaseTest$MixedCase
(reify flatland.protobuf.PersistentProtocolBufferMap$Def$NamingStrategy
(protoName [this clojure-name]
(name clojure-name))
(clojureName [this proto-name]
(keyword proto-name))))) has no effect on the above test Moreover, when loading from bytes the mixedCase key will be the one used in the internal map, thus hiding the data. |
Ok - turns out this is a "reading the code failure" on my part. The Documentation does not mention the new way of defining naming strategies in a map of options. (def mix-test (protodef MixedCaseTest$MixedCase
{:naming-strategy (reify flatland.protobuf.PersistentProtocolBufferMap$Def$NamingStrategy
(protoName [this clojure-name]
(name clojure-name))
(clojureName [this proto-name]
(keyword proto-name)))}
)) .. does work. However, I would point out that this means that "naming strategies" might not actually work as intended. |
As pointed out in ninjudd#45.
a Message with mixedCase fields will have those fields omitted when printing the message.
When printing the schema for the message, the key is printed as all-lower-case, however the value is only associated with the mixed-case key.
When printing the message out, it seems the toString method is referencing the lower-case key from the schema, which returns nil and therefore omits the key:value pair.
This may be related to #39
The text was updated successfully, but these errors were encountered: