How to ignore some fields when using snakeyaml to serialize java bean to yaml file - snakeyaml

I'd like to use snakeyaml to serialize java bean to yaml file. But I don't want to serialize all the fields of the java bean, some of them should be ignored. Is there any way to make it? Thanks

Related

Log4j2 property file support for custom filters

I am trying to use a custom filter using log4j2 in two ways below. Unfortunately I get invalid element or attribute 'filter' error. Is log4j2 xml needed for filters?
I tried with or without using package name in the filter none of which works
appender.custom.filter=com.test.util.CustomAppender
packages=com.test.util
appender.custom.filter=CustomAppender

Get access to yaml external file in Thorntail

I want to get access to external YAML file which I specify through command-line argument:
java -jar target/app-thorntail.jar -s./test.yaml
This file I need to use to get my custom properties tree by SnakeYaml.
You can use #Inject #ConfigurationValue for your custom properties, and you can #Inject a ConfigView to read the entire configuration tree. I believe that should be enough for your usecase. This approach will also provide correct values in case multiple configuration files are used.
I'm not sure if you can get access to the file itself, except maybe provide a custom main method and parse the command-line arguments yourself.

Grails - how to access properties file from GSP

I need to have access to my properties file from GSP file to get one of it's values.
I tried to find example over the web, but I couldn't.
This is a file which I created and not Grails.
Thanks!
From grails controller and gsp file, you can access your yml file properties using GrailsApplication object:
${grailsApplication.config.get('YOUR_PROPERTY_NAME)}
you can access aaplicationContext from the GSP ... so you can access any configuration property.
Just look at this entry from Mr. Haki:
http://mrhaki.blogspot.com.es/2011/11/grails-goodness-get-grailsapplication.html
If the properties file is under grails-app/i18n/ (it can be your own properties file, doesn't have to be one of the default ones) then you can access property values from the property file in a GSP using the message tag. See http://grails.org/doc/latest/ref/Tags/message.html.
If you are reading simple properties it sounds like what you want is externalized configuration
To use it in a GSP (if you really need to, but not recommended from a GSP):
${Holders.config.myPropertyKey}

How to get grails to assign Id to a legacy Java object

I have a java annotized domain object that I want to use in grails, this works fine, however all the generated templates use Id as the primary key. I tried to create a XxxConstraints.groovy file in the same package as my domain object, and added
mapping = {
id type:'assigned', name:<name of java field>, type: string
}
but that does not seem to work.
The error I get when trying to render the gsp is "class XYZ does not contain field id"
By the way I am using grails 2.1.0.
Thanks for the help in advance.
If you're talking about scaffolding views, they just have id field hardcoded, like: <g:hiddenField name="id" value="\${${propertyName}?.id}" /> (sample from edit.gsp).
Just modify your GSPs by hand to use your key field.
If it's more than one class and you don't want to generate all the views, you can install the templates into your project sources with grails install-templates and modify those to use your PK field. Maybe Groovy wrappers for Java classes will have ident() method, though not sure.
After looking at the doc, I'm in doubt if mapping{} DSL will work at all. Looks like only constraints section will work, and I believe you only need #Id annotation.

Using ANT with multiple XSD and single XJB

I have a custom external XJB file that has the schema name within it as follows :
jxb:bindings schemaLocation="completeCheck.xsd" node="/xs:schema"
Just wondering, is there a way to substitute the schema name at runtime within the XJB file using ANT(using ANT XJC) OR have a xjb binding file written such that I do not have to hardcode the schema name in it. Basically, I am trying to see if I can use a single xjb file for multiple XSDs.
Currently, I have the same xjb file all over the place with a different hardcoded schema name referred all over the place in build.xml. Any pointers are highly appreciated. I am using JAXB 2.x
Make a template from your xjb file by replacing the value of your schemaLocation attribute with some sort of marker (e.g. !!!) and save it using some other name/extension. Define a macro with an attribute such as schema-name that will use ant's replace to change the marker in the template file with your schema name and save that as the binding file to be subsequently used by xjc.
Normally, in the latest versions of XJC, you can use schema component designator. More info here :
https://jaxb.java.net/nonav/2.2.1/docs/vendorCustomizations.html#scd and https://jaxb.java.net/guide/Using_SCD_for_customizations.html

Resources