Nim: `Unable to process type: nnkBracketExpr` when unmarshal to type with Table[string, seq[string]] - nim-lang

The following type Response:
type
Response* = object
name: string
vers: string
features: Table[string, seq[string]]
which I'm trying to unmarshal a json to:
let json = parseJson(text)
let test = to(json, Response)
However to(json, Response) is throwing the following exception:
Error: unhandled exception: false Unable to process type: nnkBracketExpr
Can't figure out what I'm doing wrong, do I need to specify the features Table in another way?
Thanks

Related

Groovy OkHttpBuilder with GET Method - getting groovy.json.JsonException

Hi I'm using Groovy HTTPBuilder to make a GET call with request body similar like this:
def obj = [:]
// add the data in map - obj
def http = OkHttpBuilder.configure {
request.uri = "URL"
request.uri.path = "/path"
request.headers.put("Authorization", "token value")
request.cookie("fingerprint", "fingerprint value")
request.accept ="application/json"
request.headers.put("Content-Type", "application/json;")
def jsonBody = JsonOutput.toJson(obj)
request.body = jsonBody
response.failure { FromServer fromServer, Object body ->
assertHttpFailure(fromServer, body)
}
}
http.get()
But, getting an groovy.json.JsonException with below details
Unable to determine the current character, it is not a string, number, array, or object
The current character read is 'R' with an int value of 82
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 0
Required request body is missing: public org.springframework.http.ResponseEntity<java.util.List
Any suggestions ? why request body says missing

Java illegal argument exception when setting Json value using groovy

I am trying to set 'code' value as 'Test2' for given Json using groovy but i get Java illegal argument exception while setting the value.
Raw request:
{
"langauageCode": "en-US",
"Test": [{
"_modificationTypeCode": "added",
"allocationTypeCode": "3",
"code": "Test1"
}]
}
Here is the code I am using
def jsonRequest = slurper.parseText(rawRequest)
def builder = new JsonBuilder(jsonRequest)
builder.content.Test.code ='Test2' //Throwing java illegal argument but when I print using log.info I get the value
log.info("testbuilder " + builder.content.Test.code)
Can some one please let me know while I am setting the value why I am getting Java illegal argument exception?
It's because Test is an array. if you want to set the code, you need to:
builder.content.Test[0].code = 'Test2'

TypeError: Cannot read property 'Grid' of undefined thrown in Table.forceUpdateGrid

I am attempting to call tableInstance.forceUpdateGrid() inside a Promise.then() callback and it is throwing an exception TypeError: Cannot read property 'Grid' of undefined
Looking at the following code
_createClass(Table, [{
key: 'forceUpdateGrid',
value: function forceUpdateGrid() {
this.Grid.forceUpdate();
}
the this reference is undefined...
the only thing I can think of is that in-between the initial BE api call and the Promise.then() handler, there has been a props change that has caused the containing component to re-render and maybe the tableInstance reference no longer points to the correct instance?
Can anyone help?
(1) Use fat arrow functions to get this reference inside function :-
_createClass(Table, [{
key: 'forceUpdateGrid',
value: forceUpdateGrid = () => {
this.Grid.forceUpdate();
}
(2)Or,
let thisRef = this;
_createClass(Table, [{
key: 'forceUpdateGrid',
value: function forceUpdateGrid() {
thisRef.Grid.forceUpdate();
}
i hope it helps!

How to assign an index signature to a object's value?

Giving the following code:
export function objToStr(object: object): string {
let str = [];
for (let p in object) {
if (object.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(object[p]))
}
}
return str.join("&")
}
I get the error from object[p]:
Element implicitly has an 'any' type because type '{}' has no index signature. [7017]
I tried with
encodeURIComponent((<any>object[p]))
encodeURIComponent(object[p]: any)
But I still get the error. I find typing everything quite confusing, there is so much types out there.
If someone can tell me what Typescript wants from me there, it would help a lot, it's the last error message and then I'm done switching my code form JS to TS.
EDIT
I had to add "noImplicitAny": true to test the setting as I wasn't sure what is was doing and how the code would react to it.
Turning it to false I now get:
Argument of type 'string' is not assignable to parameter of type 'never'. [2345] for the part insite str.push
Error appears because you have compilerOptions.noImplicitAny = true at tsconfig.json. As error suggests, add index signature to object variable:
let object: { [index: string]: any } = {};
let str: string[] = [];
i.e. any will be specified explicit.

TypeScript warning => TS7017: Index signature of object type implicitly has any type

I am getting the following TypeScript warning -
Index signature of object type implicitly has any type
Here is the code that cases the warning:
Object.keys(events).forEach(function (k: string) {
const ev: ISumanEvent = events[k]; // warning is for this line!!
const toStr = String(ev);
assert(ev.explanation.length > 20, ' => (collapsed).');
if (toStr !== k) {
throw new Error(' => (collapsed).');
}
});
can anyone determine from this code block why the warning shows up? I cannot figure it out.
If it helps this is the definition for ISumanEvent:
interface ISumanEvent extends String {
explanation: string,
toString: TSumanToString
}
You could add an indexer property to your interface definition:
interface ISumanEvent extends String {
explanation: string,
toString: TSumanToString,
[key: string]: string|TSumanToString|ISumanEvent;
}
which will allow you to access it by index as you do: events[k];. Also with union indexer it's better to let the compiler infer the type instead of explicitly defining it:
const ev = events[k];

Resources