[YANGTOOLS-160] String needs to be changed to Object (or Enum) in the method TypeDefinitionAwareCodec$EnumCodecStringImpl.serialize Created: 12/May/14 Updated: 10/Apr/22 Resolved: 21/May/14 |
|
| Status: | Verified |
| Project: | yangtools |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | ||
| Reporter: | Flavio Fernandes | Assignee: | Tom Pantelis |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Operating System: All |
||
| External issue ID: | 990 |
| Description |
|
While following the md-sal tutorial on ping: https://wiki.opendaylight.org/view/Ping I see the exception below when exercising the RPC rest call as shown: http://localhost:8080/restconf/operations/ping:send-echo } — From: Tom Pantelis <tompantelis@gmail.com> That code is in the yangtools project - check the contributor list. I would say create a bug in the yangtools project to get the ball rolling. I definitely think String needs to be changed to Object (or Enum) in the method and generic type signatures similar to what was done in On Mon, May 12, 2014 at 9:21 AM, Flavio Fernandes <ffernand@redhat.com> wrote: Thanks, Tom. Yeah, I agree 100%. I played with TypeDefinitionAwareCodec.java as much as I could to make it work, but my Java skills are just Do you know who would be the most familiar with that code? I’m trying to reach Tony T. but no answer yet. Maybe he is busy at the OpenStack Summit. Chhers, — flavio On May 11, 2014, at 12:56 PM, Tom Pantelis <tompantelis@gmail.com> wrote: Flavio, I'm not familiar with this code but it looks like the ex occurs when invoking the EnumCodecStringImp.serialize method because the JVM can't cast the input parameter of type EchoResult enum instance to a String. It seems to me that EnumCodecStringImp.serialize should take an Object param - all it does anyway is return toString() on the param. Tom On Sat, May 10, 2014 at 6:17 PM, Flavio Fernandes <ffernand@redhat.com> wrote: While doing the MD-SAL tutorial on ping ( https://wiki.opendaylight.org/view/Ping ), I hit an exception that looks like this: ... Thanks, – flavio |
| Comments |
| Comment by Tom Pantelis [ 13/May/14 ] |
|
This same issue occurs in the toaster example when invoking the make-toast RPC via restconf: HTTP Method => POST } osgi> 2014-05-06 18:35:47.476 EDT [http-bio-8080-exec-1] ERROR o.o.c.sal.restconf.impl.RestCodec - ClassCastException was thrown when codec is invoked with parameter Up |
| Comment by Tom Pantelis [ 13/May/14 ] |
|
In the Toaster example, the exception actually occurs on a GET to http://localhost:8080/restconf/operational/toaster:toaster when attempting to convert the ToasterStatus enum value. The node value passed to EnumCodecStringImpl.serialize is an Enum type and not a String. RestCodec$ObjectCodec.serialize actually catches the exception, logs it and returns the original input value: try { .... } else { else { logger.debug("Codec for type \"" + type.getQName().getLocalName() + "\" is not implemented yet."); return null; } } JsonMapper.writeValueOfNodeByType then takes the returned ToasterStatus enum and "toString"'s it via String.valueOf: String value = String.valueOf(RestCodec.from(baseType, So the exception is actually benign - RestCodec.from fails internally but the JsonMapper works correctly and the json data is returned correctly to the client. Changing EnumCodecStringImpl.serialize to take an Object should avoid the exception. |
| Comment by Tom Pantelis [ 14/May/14 ] |
|
The root cause of this issue is actually in the codec generated toDomStatic method: org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.Toaster$ToasterStatus getToasterStatus = } Instead of returning the enum, it should call: org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.Toaster$ToasterStatus$Codec$DOM.toDomValue |
| Comment by Tom Pantelis [ 20/May/14 ] |
|
This is issue was resolved by an upstream merge. |
| Comment by Tony Tkacik [ 21/May/14 ] |
|
Bugfix was: https://git.opendaylight.org/gerrit/7019 |
| Comment by Flavio Fernandes [ 21/May/14 ] |
|
Fixed as of: org.opendaylight.controller.version = 0.1 Still seeing: https://gist.github.com/0030bb1c3f3231846f3e |