Serializing Typesafe Config objects - config

I'd like to persist a Config object (https://github.com/typesafehub/config) as a serialized string(maybe JSON ??) and read it back when required. However, I didnt find any API on the Config api docs that supports. Any help on this is appreciated.
I tried
config.toString
but the result looks like
Config(SimpleConfigObject({...data}))

Try this:
config.root().render(ConfigRenderOptions.concise())

Of course you can also adjust a few parameters, for example:
val renderOptions = ConfigRenderOptions
.defaults()
.setOriginComments(false)
.setComments(false)
.setFormatted(true)
println(config.root().render(renderOptions))

Related

Minecraft Spigot I cannot get String from Component

Hello Support I can't get the String from a Component. I did this with 2 ways with bad results.
TextComponent textComponent = (TextComponent) item.displayname;
return textComponent.content();
The result of this is a error with Casting
and
return PlainTextComponentSerializer.plainText().serialize(item.displayname);
The result of this is Literaly "chat.square_brackets" which is weird.
Please Help. Thanks
I also was having trouble with this. Here's what I found to work for me. Full disclosure that I'm developing my plugin on the PaperMC 1.16 fork and not Spigot. So it's possible that this may not work for you, either because it isn't a part of Spigot or because you are working in a version that this feature is not a part of.
To start, I would first check to make sure that we are both on the same page. For me, the component objects being used are from a package called net.kyori.adventure.text if yours are not provided by this package I don't know that this solution will work for you.
Also as mentioned by others, accessing the displayName directly on the ItemStack isn't going to give the desired results. Instead, you need to do itemStack.getItemMeta().displayName(). This method should then return a net.kyori.adventure.text.Component; once you have the component you need to serialize it using one of the serializers from the previously mentioned package.
That will look something like this:
Component itemDisplayName = itemStack.getItemMeta().displayName()
PlainComponentSerializer plainSerializer = PlainComponentSerializer.plain();
String itemName = plainSerializer.serialize(itemDisplayName);
The package that the serializer is from is: net.kyori.adventure.text.serializer.plain.PlainComponentSerializer
I don't understand how you can access to the displayname field in ItemStack in the Spigot API.
You should use ItemMeta to manage display name. To get the item meta, you should use ItemStack#getItemMeta.
Don't forget to check if the item as a meta with hasItemMeta. You can also use hasDisplayName to be sure that the display name is valid.

Bind Key Vault settings to class

In ASP.NET Core, if reading configuration from a JSON app.settings file I can bind a section to an object like this:
services.Configure<MyPocoConfig>(Configuration.GetSection("Section"))
Is there a straightforward way to do this with a group of settings that are read from Azure Key Vault? I am following the guide as described in the MSDN documentation here https://learn.microsoft.com/en-us/azure/key-vault/vs-key-vault-add-connected-service#access-your-secrets-in-code
I can manually map them like this:
services.Configure<MyPocoConfig>(myPoco =>
{
myPoco.Option1 = Configuration["Option1"];
myPoco.Option2 = Configuration["Option2"];
});
I just wondered if there was a way to automap them as it works for config stored in app.settings JSON. I'm sure it could be done with reflection but I was hoping there'd be a built in way.
I tried putting the settings into a category using the category--setting syntax described in the article and reading them with services.Configure<MyPocoConfig>(Configuration.GetSection("category")), but this doesn't work.
Edit:
It is now possible as of 2020 to put settings into a category using the category--setting syntax and read them like services.Configure<MyPocoConfig>(Configuration.GetSection("category"))
You can achieve the same by naming your Secret in the following pattern.
Section--Option1
Section--Option2
And you can use the following to get the values by section and .NetCore automatically maps it.
services.Configure<MyPocoConfig>(Configuration.GetSection("Section"))
Refer link https://learn.microsoft.com/en-us/aspnet/core/security/key-vault-configuration?view=aspnetcore-2.2#bind-an-array-to-a-class

What should i use to parse and unparse data like : "a:66:{s:24:"images";a:0:{} s:26:"thumbnail_image";s:0:"";:"... ?

I'm working with ThemeFuse I found this data format. But it not looks like anything I saw before.
a:66:{s:24:"autotrader_slider_images";a:0:{}s:26:"autotrader_thumbnail_image";s:0:"";s:19:"seek_property_price";s:0:"";s:23:"seek_property_vat_price";s:0:"";s:21:"seek_property_mileage";s:0:"";s:25:"seek_property_engine_size";s:0:"";s:30:"seek_property_engine_power_bhp";s:0:"";s:29:"seek_property_engine_power_kw";s:0:"";s:23:"seek_property_reduction";s:1:"0";s:25:"seek_property_consumption";s:1:"0";s:20:"seek_property_origin";s:0:"";s:22:"seek_property_emission";s:13:"super emitivo";s:23:"autotrader_vehicle_type";s:3:"SUV";s:20:"autotrader_fuel_type";s:6:"Diesel";s:23:"autotrader_gearbox_type";s:9:"Automatic";s:17:"autotrader_status";s:6:"Intact";s:16:"autotrader_color";s:5:"White";s:18:"seek_property_year";s:0:"";s:26:"autotrader_enable_comments";s:5:"false";s:29:"autotrader_enable_breadcrumbs";s:4:"true";s:25:"autotrader_header_element";s:4:"none";s:23:"autotrader_header_image";s:0:"";s:23:"autotrader_header_title";s:0:"";s:24:"autotrader_select_slider";s:2:"-1";s:19:"autotrader_page_map";s:0:"";s:19:"autotrader_map_text";s:11:"We are here";s:19:"autotrader_map_zoom";s:2:"13";s:25:"autotrader_search_element";s:4:"none";s:22:"autotrader_content_top";s:0:"";s:26:"autotrader_content_bottom1";s:0:"";s:25:"autotrader_footer_element";s:4:"none";s:31:"autotrader_select_slider_footer";s:2:"-1";s:25:"autotrader_content_bottom";s:0:"";s:26:"autotrader_content_bottom2";s:0:"";s:23:"autotrader_top_ad_space";s:5:"false";s:23:"autotrader_top_ad_image";s:0:"";s:21:"autotrader_top_ad_url";s:0:"";s:25:"autotrader_top_ad_adsense";s:0:"";s:30:"autotrader_bfcontent_ads_space";s:5:"false";s:25:"autotrader_bfcontent_type";s:5:"image";s:27:"autotrader_bfcontent_number";s:3:"one";s:31:"autotrader_bfcontent_ads_image1";s:0:"";s:29:"autotrader_bfcontent_ads_url1";s:0:"";s:33:"autotrader_bfcontent_ads_adsense1";s:0:"";s:31:"autotrader_bfcontent_ads_image2";s:0:"";s:29:"autotrader_bfcontent_ads_url2";s:0:"";s:33:"autotrader_bfcontent_ads_adsense2";s:0:"";s:31:"autotrader_bfcontent_ads_image3";s:0:"";s:29:"autotrader_bfcontent_ads_url3";s:0:"";s:33:"autotrader_bfcontent_ads_adsense3";s:0:"";s:31:"autotrader_bfcontent_ads_image4";s:0:"";s:29:"autotrader_bfcontent_ads_url4";s:0:"";s:33:"autotrader_bfcontent_ads_adsense4";s:0:"";s:31:"autotrader_bfcontent_ads_image5";s:0:"";s:29:"autotrader_bfcontent_ads_url5";s:0:"";s:33:"autotrader_bfcontent_ads_adsense5";s:0:"";s:31:"autotrader_bfcontent_ads_image6";s:0:"";s:29:"autotrader_bfcontent_ads_url6";s:0:"";s:33:"autotrader_bfcontent_ads_adsense6";s:0:"";s:31:"autotrader_bfcontent_ads_image7";s:0:"";s:29:"autotrader_bfcontent_ads_url7";s:0:"";s:33:"autotrader_bfcontent_ads_adsense7";s:0:"";s:21:"autotrader_hook_space";s:5:"false";s:21:"autotrader_hook_image";s:0:"";s:19:"autotrader_hook_url";s:0:"";s:23:"autotrader_hook_adsense";s:0:"";}
What should I use to parse and unparse this format?
This is serialized PHP array.
All you need to do is to unserialize it.
http://php.net/manual/en/function.unserialize.php

Recursive/Exploded uri variable with restlet

Does Restlet support exploded path variable (reference to URI Template RFC)?
An example would be /documents{/path*} where path can be for example "a/b/c/d/e".
This syntax doesn't seem to work with Restlet.
I'm creating a folder navigation api and I can have variable path depth, but I'm trying to have only one resource on the server side to handle all the calls. Is this something I can do with Restlet? I suppose I could create a custom router but if there is another way to do this I would like to know.
Thanks
It is possible to support this using matching modes.
For example:
myRouter.attach("/documents{path}",
MyResource.class).setMatchingMode(Template.START_WITH);
Hope this helps!
I'm doing the following
myRouter.attach("/documents/{path}", MyResource.class).setMatchingMode(Template.START_WITH);
Now I do get inside the resource GET method, but if I request the value of the path variable, I only get the first part (for example, /documents/a/b/c, path returns "a".) I use getRequest().getAttributes().get("path") to retrieve the value. Am I doing something wrong ?
Mathieu

Programmatically explore feature definitions

Is there any API to explore the definition of a feature (like the reflexion for code)?
My goal is for example to be able to do:
var myFeature = GetMyFeature("my feature guid")
var contentTypes = myFeature.Definition.ContentTypes
I know I can parse the xml files of the feature, but I'd like to avoid it.
Yes, you want to look at the SPFeature and SPFeatureDefinition types in the server object model.