Additional fields retrieved while using reflection - methods

I am writing a simple java class that makes use of the reflection API to find out the declared fields in the java.lang.class. Following is the piece of java code I have written.
Field[] fields = String.class.getDeclaredFields();
for (Field f : fields) {
System.out.println("Field name: " + f.getName());
}
I am getting the following output when I run this program.
Field name: serialVersionUID
Field name: CASE_INSENSITIVE_ORDER
Field name: ascii
Field name: stringArray
Field name: stringArraySize
Field name: enableCopy
Field name: value
Field name: offset
Field name: count
Field name: hashCode
Field name: hashCode32
Field name: seed
Field name: startCombiningAbove
Field name: endCombiningAbove
Field name: upperValues
Field name: serialPersistentFields
When I looked at the source code of the String class, I found that there were only 6 fields defined for the class in API.
I am not able to figure out where these additional fields are coming from in the output. Please help here.

There is nothing wrong with your code; when I run it, I get the expected output:
Field name: value
Field name: hash
Field name: serialVersionUID
Field name: serialPersistentFields
Field name: CASE_INSENSITIVE_ORDER
I'm guessing that you're using a non-Oracle Java Virtual Machine that adds (either in its bundled libraries or through some runtime magic) adds some nonstandard fields to the String class.

Related

Filebeat Script Processor Event.Get All Fields In Log

I am looking to get all of the fields in a record in filebeat using the Script processor and perform an action on them. Using the event.Get() from the script processor, it says, "Get a value from the event (either a scalar or an object). If the key does not exist null is returned. If no key is provided then an object containing all fields is returned."
https://www.elastic.co/guide/en/beats/filebeat/current/processor-script.html
Therefore, my question is, what would I do to ensure that no key is provided to get an object that contains all of the fields are returned?
The event.Get() field will provide the top level fields. To look through these top level fields, use a for loop like:
- script:
lang: javascript
id: get_fields
source: >
function process(event) {
var a = event.Get();
for (var key in a) {
if(event.Get(key) == ""){
event.Delete(key);
}
}
}
I am unsure how to do this for nested fields in this way nor have I tried to extend it to nested fields, but this is how it works for now.

OpenApi 3.0: How to define uniqueness of array elements based upon a key (property) in object that is used as an element schema for that array?

I am having following schema defined in 'components' section of my openApi 3.0:
schema1:
required:
- prop1
- prop2
properties:
prop1
prop2:
enum:
- option1
- option2
prop3
This Schema is being used to define array elements in another schema as:
schema2:
required:
- prop4
- items
- prop6
properties:
prop4
prop5:
type: array
items:
$ref: '#/components/schemas/schema1'
maxItems: 2
prop6
Now in prop5 of Schema 2, I want the elements of array having unique value of prop2. Any ideas how to achieve this.
This is not possible as of OpenAPI 3.1 and JSON Schema 2020-12. Currently such validations need to be implemented on the backend.
Here's the corresponding feature request in one of the JSON Schema issue trackers:
https://github.com/json-schema-org/json-schema-vocabularies/issues/22
OpenAPI Schema is based on JSON Schema so any new schema keywords will come from JSON Schema.

Formatting ActiveRecord results for parsing?

I have a database with entries which I can fetch using ActiveRecord. Currently, using something like post.to_yaml yields:
!ruby/object:Post
concise_attributes:
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: id
value_before_type_cast: 1
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: user
value_before_type_cast: efy5qC5YmJNml23JowOUrlmfN0D2
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: content
value_before_type_cast: bol4
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: location
value_before_type_cast: '123'
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: timestamp
value_before_type_cast: '12:00'
new_record: false
The exact collection i'm returning is as follow: record = Post.order(:timestamp).offset(15 * 0).first(15)
This returned result contains several fields which will be returned to a Flutter application. The data will populate a widget with several fields such as content, date and location, all of which is returned by the above query.
I could use a Dart library to parse the YAML, but is there a better way to condense the returned values so that only the necessary fields are shown?
As per the description shared it seems like you have data from the database and you now need to select only particular fields that needs to be shown.
As per current scenario you could use something like:
post.as_json(only: [:content, :name, :location])
Else you could modify the query you are using by using select statement for selecting specific attributes from database.
Post.select(:name, :content, :location)
Hope it helps!!

Should I write two times each objects as 'input' and 'type' in a graphql schema file

I have to use a Java object in GraphQL in response as well as in request.
Should I have to write two times each objects as 'input' and 'type' in a GraphQL schema file? For getting that object in request as well as in response.
Should I define the same object two times with input and type?
file: test.graphqls
input Employee {
id: Integer
name: String
dept: String
active: String
}
type Employee {
id: Integer
name: String
dept: String
active: String
}
Yes, because the type system rules are very different for input and output types. Input types can not be unions, can not implement interfaces etc, so you can not simply use the same definition for both purposes.
Moreover, you must give each type a unique name. So it should be Employee and EmployeeInput for example.

Doctrine2 + CodeIgniter and database table creation issue

I'm using Doctrine2 with codeIgniter, I've created some models in yml format. Using command line I've created the Proxies and Entities. When I'm trying to create the database tables, I'm getting the following error:
[Doctrine\ORM\Mapping\MappingException]
Invalid mapping file 'Entities.category.dcm.yml' for class
'Entities\category'.
Here's Entities.category.dcm.yml:
Entities\Category:
type: entity
table: categories
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
name:
type: string
length: 50
nullable: false
description:
type: string
length: 255
First of all, check the paths configured for your entities and for the YML mapping driver.
Also, your Entities.category.dcm.yml contains mappings for Entities\Category, and not Entities\category.
As you can see in the base FileDriver Doctrine ORM does direct matching for mapped classes, and applies no normalization on the class names. Category and category are therefore different.

Resources