We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
as reference mentioned, java instant type can be formatted as following:
https://github.com/lazee/freemarker-java-8#ballot_box_with_check-javatimeinstant
${myinstant.format()}
but It doesnt support format as coded like this:
@Override public TemplateModel getForType(String s) throws TemplateModelException { if (METHOD_FORMAT.equals(s)) { return new InstantFormatter(getObject()); } throw new TemplateModelException(METHOD_UNKNOWN_MSG + s); } public class InstantFormatter extends AbstractFormatter<Instant> implements TemplateMethodModelEx { public InstantFormatter(Instant obj) { super(obj); } @Override public Object exec(List list) throws TemplateModelException { return getObject().toString(); // format ignored } }
generated value is always getObject().toString() so formatting wont work
getObject().toString()
I've searched other types of type, and find out this:
public class LocalDateFormatter extends AbstractFormatter<LocalDate> implements TemplateMethodModelEx { public LocalDateFormatter(LocalDate obj) { super(obj); } @Override public Object exec(List list) throws TemplateModelException { return getObject().format(createDateTimeFormatter(list, 0, DateTimeFormatter.ISO_LOCAL_DATE)); } }
in your code-context, instant type also can be formatted.
public class FormattableInstantAdapter extends AbstractAdapter<Instant> implements AdapterTemplateModel, TemplateScalarModel, TemplateHashModel { public FormattableInstantAdapter(Instant obj, BeansWrapper wrapper) { super(obj, wrapper); } @Override public TemplateModel getForType(String s) throws TemplateModelException { if (METHOD_FORMAT.equals(s)) { return new InstantFormatter(getObject()); } throw new TemplateModelException(METHOD_UNKNOWN_MSG + s); } public class InstantFormatter extends AbstractFormatter<Instant> implements TemplateMethodModelEx { public InstantFormatter(Instant obj) { super(obj); } @Override public Object exec(List list) throws TemplateModelException { return createDateTimeFormatter(list, 0, DateTimeFormatter.ISO_LOCAL_DATE_TIME) .withZone(ZoneId.systemDefault()) // instant use UTC as default .format(getObject()); } } }
The text was updated successfully, but these errors were encountered:
Fixed in version 2.1.0 that will be released soon
Sorry, something went wrong.
No branches or pull requests
as reference mentioned, java instant type can be formatted as following:
https://github.com/lazee/freemarker-java-8#ballot_box_with_check-javatimeinstant
but It doesnt support format as coded like this:
I've searched other types of type, and find out this:
in your code-context, instant type also can be formatted.
The text was updated successfully, but these errors were encountered: