converters

Custom string formatting in Grails JSON marshaller

你说的曾经没有我的故事 提交于 2019-12-06 15:49:13
问题 I am looking for a way to do some string formatting through Grails JSON conversion, similar to custom formatting dates, which I found in this post. Something like this: import grails.converters.JSON; class BootStrap { def init = { servletContext -> JSON.registerObjectMarshaller(String) { return it?.trim() } } def destroy = { } } I know custom formatting can be done on a per domain class basis, but I am looking for a more global solution. 回答1: Try to create custom marshaller that use specific

How to return specific date format as JSON in Grails?

亡梦爱人 提交于 2019-12-04 07:46:16
问题 In Grails, you can use the JSON converters to do this in the controller: render Book.list() as JSON The render result is [ {"id":1, "class":"Book", "author":"Stephen King", "releaseDate":'2007-04-06T00:00:00', "title":"The Shining"} ] You can control the output date by make a setting in Config.groovy grails.converters.json.date = 'javascript' // default or Javascript Then the result will be a native javascript date [ {"id":1, "class":"Book", "author":"Stephen King", "releaseDate":new Date

Converting Integers to Date in R

∥☆過路亽.° 提交于 2019-12-04 05:42:15
问题 I want to convert my integer column to Date. the integer number looks like this (20160101). When using the as.Date function and by typing the origin argument to be "2016-01-02" the generate new column has the following value which is wrong "55197-07-06". So it has nothing to do with the write value. What could be the mistake I tried so many codes and this is one of them: data$newVar = as.Date(data$YearMonthDay, origin="2016-01-02") Also, my dates are all in 2016 year so I want to format the

javax.el.PropertyNotFoundException: itemLabel=“#{projet.nomProjet}”: Property 'nomProjet' not found on type java.lang.String

亡梦爱人 提交于 2019-12-02 20:11:54
问题 I'm trying to apply a JSF converter to an Entity inside a selectOneMenu, but the converter is not recognized, I get this warning in my xhtml file, <<"nomProjet" cannot be resolved>> and when I run the application I'm getting Error HTTP 500 : itemLabel="#{projet.nomProjet}": Property 'nomProjet' not found on type java.lang.String Here is my code: The selectOneMenu in my view <p:selectOneMenu id="projet" converter="projetConverter" value="# {affectation.selectedProjet}" > <f:selectItems var=

How to return specific date format as JSON in Grails?

陌路散爱 提交于 2019-12-02 16:21:40
In Grails, you can use the JSON converters to do this in the controller: render Book.list() as JSON The render result is [ {"id":1, "class":"Book", "author":"Stephen King", "releaseDate":'2007-04-06T00:00:00', "title":"The Shining"} ] You can control the output date by make a setting in Config.groovy grails.converters.json.date = 'javascript' // default or Javascript Then the result will be a native javascript date [ {"id":1, "class":"Book", "author":"Stephen King", "releaseDate":new Date(1194127343161), "title":"The Shining"} ] If I want to get a specific date format like this: "releaseDate":

Question regarding using only setters and variables correctly

孤街浪徒 提交于 2019-12-02 14:05:00
问题 I am having an issue with my current programming assignment. I feel as though I am very close to having it correct, but something is off. I know that I have to do something different in order to make the program function correctly, as it doesn't work right now, but I am not sure what it is. I am struggling specifically with how to use a single private variable to make both kinds of temperatures. Here is the assignment: Make a Temperature class. The class should have a function for setting the

Java - convert unix time in miliseconds with time zone to timestamp

五迷三道 提交于 2019-12-02 10:23:51
问题 I have a string for example: 1517439600000+0100 and I want to convert it to unix time in miliseconds with no timezone. how can I do it? p.s. 1) I cant use substring(0,5) and add 3.6m miliseconds to the string because I have a lot of time zone once is +0100 and then is +0200 and etc... 2) if it more easier to convert to regular timestamp like YYYY-mm-dd hh:mm:ss it should be fine. 回答1: You can do something like: String sign = "+"; String [] parts = time.split(sign); Long millis = Long

Java - convert unix time in miliseconds with time zone to timestamp

末鹿安然 提交于 2019-12-02 05:15:10
I have a string for example: 1517439600000+0100 and I want to convert it to unix time in miliseconds with no timezone. how can I do it? p.s. 1) I cant use substring(0,5) and add 3.6m miliseconds to the string because I have a lot of time zone once is +0100 and then is +0200 and etc... 2) if it more easier to convert to regular timestamp like YYYY-mm-dd hh:mm:ss it should be fine. You can do something like: String sign = "+"; String [] parts = time.split(sign); Long millis = Long.parseLong(parts[0]); String zoneOffset = sign + parts[1]; LocalDate date = Instant.ofEpochMilli(millis).atZone

convert integer to 32-bit binary in c

老子叫甜甜 提交于 2019-12-01 11:29:34
I'm writing a program to convert an integer to 32-bit binary. The problem is with the output - it comes backwards. #include <stdio.h> int main() { long number, binary, num2; printf("Enter an integer: "); scanf("%ld", &number); for (num2 = (number * 2) / 2; num2 > 0; num2 /= 2) { binary = num2 % 2; printf("%ld", binary); } putchar('\n'); return 0; } So if I put '6' it shows as 011 and it has to be 110 Also, how do I output the rest of '0's? So that the whole output in this case would be: 00000000 00000000 00000000 00000110 You compute digits starting from the right, which is why your output

Converting object properties to array of objects

三世轮回 提交于 2019-12-01 07:39:44
问题 I'm getting output that looks like this: {'1536135941922': 'true', '1536135962942': 'false', '1536135986966': 'false', '1536135989968': 'true'} and I need it to look like this: [{'1536135941922': 'true'}, {'1536135962942': 'false'}, {'1536135986966': 'false'}, {'1536135989968': 'true'}] So my front can consume it. What is the way that I can convert it? 回答1: You can use Object.entries() and .map() methods to get the desired output: let data = { '1536135941922': 'true', '1536135962942': 'false'